From 4e6fa4dad5a7e9f979c5726e269a55114683d8c8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Apr 2022 07:02:16 +0000 Subject: [PATCH 001/103] Auto-generated commit 2d339a908e5299afe32122c0c1a0e42a31d65a4a --- CONTRIBUTORS | 28 + LICENSE | 481 +++++++++ NOTICE | 1 + README.md | 549 ++++++++++ index.d.ts | 359 +++++++ index.mjs | 4 + index.mjs.map | 1 + package.json | 73 ++ stats.html | 2689 +++++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 4185 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..264c9cb --- /dev/null +++ b/README.md @@ -0,0 +1,549 @@ + + +# Typed Array Pool + +[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] + +> Allocate typed arrays from a typed array memory pool. + + + +
+ +
+ + + + + + + +
+ +## Usage + +```javascript +import typedarraypool from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-pool@esm/index.mjs'; +``` + +#### typedarraypool( \[dtype] ) + +Returns an **uninitialized** [typed array][mdn-typed-array] having a specified data type `dtype`. + +```javascript +var arr = typedarraypool(); +// returns [] + +// ... + +typedarraypool.free( arr ); +``` + +The function recognizes the following data types: + +- `float64`: double-precision floating-point numbers (IEEE 754) +- `float32`: single-precision floating-point numbers (IEEE 754) +- `complex128`: double-precision complex floating-point numbers +- `complex64`: single-precision complex floating-point numbers +- `int32`: 32-bit two's complement signed integers +- `uint32`: 32-bit unsigned integers +- `int16`: 16-bit two's complement signed integers +- `uint16`: 16-bit unsigned integers +- `int8`: 8-bit two's complement signed integers +- `uint8`: 8-bit unsigned integers +- `uint8c`: 8-bit unsigned integers clamped to `0-255` + +By default, the output [typed array][mdn-typed-array] is `float64`. To specify an alternative data type, set the `dtype` parameter. + +```javascript +var arr = typedarraypool( 'int32' ); +// returns [] + +// ... + +typedarraypool.free( arr ); +``` + +#### typedarraypool( length\[, dtype] ) + +Returns an **uninitialized** [typed array][mdn-typed-array] having a specified `length` from a [typed array][mdn-typed-array] memory pool. + +```javascript +var arr1 = typedarraypool( 5 ); +// returns + +var arr2 = typedarraypool( 5, 'uint8' ); +// returns + +// ... + +typedarraypool.free( arr1 ); +typedarraypool.free( arr2 ); +``` + +#### typedarraypool( typedarray\[, dtype] ) + +Returns a pooled [typed array][mdn-typed-array] from another [typed array][mdn-typed-array]. + +```javascript +var arr1 = typedarraypool( [ 5.0, -3.0, 2.0 ] ); +// returns [ 5.0, -3.0, 2.0 ] + +var arr2 = typedarraypool( arr1 ); +// returns [ 5.0, -3.0, 2.0 ] + +var arr3 = typedarraypool( arr1, 'int32' ); +// returns [ 5, -3, 2 ] + +// ... + +typedarraypool.free( arr1 ); +typedarraypool.free( arr2 ); +typedarraypool.free( arr3 ); +``` + +#### typedarraypool( obj\[, dtype] ) + +Returns a pooled [typed array][mdn-typed-array] from an array-like `object`. + +```javascript +var arr1 = typedarraypool( [ 0.5, 0.5, 0.5 ] ); +// returns [ 0.5, 0.5, 0.5 ] + +var arr2 = typedarraypool( [ 0.5, 0.5, 0.5 ], 'float32' ); +// returns [ 0.5, 0.5, 0.5 ] + +// ... + +typedarraypool.free( arr1 ); +typedarraypool.free( arr2 ); +``` + +#### typedarraypool.malloc( \[dtype] ) + +Returns an **uninitialized** [typed array][mdn-typed-array] having a specified data type `dtype`. + +```javascript +var arr1 = typedarraypool.malloc(); +// returns [] + +var arr2 = typedarraypool.malloc( 'int32' ); +// returns [] + +// ... + +typedarraypool.free( arr1 ); +typedarraypool.free( arr2 ); +``` + +#### typedarraypool.malloc( length\[, dtype] ) + +Returns an **uninitialized** [typed array][mdn-typed-array] having a specified `length` from a [typed array][mdn-typed-array] memory pool. + +```javascript +var arr1 = typedarraypool.malloc( 5 ); +// returns + +var arr2 = typedarraypool.malloc( 5, 'uint8' ); +// returns + +// ... + +typedarraypool.free( arr1 ); +typedarraypool.free( arr2 ); +``` + +#### typedarraypool.malloc( typedarray\[, dtype] ) + +Returns a pooled [typed array][mdn-typed-array] from another [typed array][mdn-typed-array]. + +```javascript +var arr1 = typedarraypool.malloc( [ 5.0, -3.0, 2.0 ] ); +// returns [ 5.0, -3.0, 2.0 ] + +var arr2 = typedarraypool.malloc( arr1 ); +// returns [ 5.0, -3.0, 2.0 ] + +var arr3 = typedarraypool.malloc( arr1, 'int32' ); +// returns [ 5, -3, 2 ] + +// ... + +typedarraypool.free( arr1 ); +typedarraypool.free( arr2 ); +typedarraypool.free( arr3 ); +``` + +#### typedarraypool.malloc( obj\[, dtype] ) + +Returns a pooled [typed array][mdn-typed-array] from an array-like `object`. + +```javascript +var arr1 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ] ); +// returns [ 0.5, 0.5, 0.5 ] + +var arr2 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ], 'float32' ); +// returns [ 0.5, 0.5, 0.5 ] + +// ... + +typedarraypool.free( arr1 ); +typedarraypool.free( arr2 ); +``` + +#### typedarraypool.calloc( \[dtype] ) + +Returns a **zero-initialized** [typed array][mdn-typed-array] having a specified data type `dtype`. + +```javascript +var arr1 = typedarraypool.calloc(); +// returns [] + +var arr2 = typedarraypool.calloc( 'int32' ); +// returns [] + +// ... + +typedarraypool.free( arr1 ); +typedarraypool.free( arr2 ); +``` + +#### typedarraypool.calloc( length\[, dtype] ) + +Returns a **zero-initialized** [typed array][mdn-typed-array] having a specified `length` from a [typed array][mdn-typed-array] memory pool. + +```javascript +var arr1 = typedarraypool.calloc( 5 ); +// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] + +var arr2 = typedarraypool.calloc( 5, 'uint8' ); +// returns [ 0, 0, 0, 0, 0 ] + +// ... + +typedarraypool.free( arr1 ); +typedarraypool.free( arr2 ); +``` + +#### typedarraypool.free( buf ) + +Frees a [typed array][mdn-typed-array] or typed array [buffer][mdn-arraybuffer] for use in a future allocation. + +```javascript +var arr = typedarraypool( 10, 'float64' ); +// returns + +// ... + +// Free the allocated typed array for use in a future allocation: +typedarraypool.free( arr ); + +// Create another typed array: +arr = typedarraypool( 10, 'float64' ); +// returns + +// ... + +// Free the allocated typed array buffer for use in a future allocation: +typedarraypool.free( arr.buffer ); +``` + +#### typedarraypool.clear() + +Clears the [typed array][mdn-typed-array] pool allowing garbage collection of previously allocated (and currently free) [array buffers][mdn-arraybuffer]. + +```javascript +var arr = typedarraypool( 10, 'float64' ); +// returns + +// ... + +typedarraypool.free( arr ); + +// ... + +// Clear all freed buffers: +typedarraypool.clear(); +``` + +#### typedarraypool.highWaterMark + +**Read-only** property returning the pool's high water mark (in bytes). + +```javascript +var limit = typedarraypool.highWaterMark; +// returns +``` + +Once a high water mark is reached, [typed array][mdn-typed-array] allocation **fails**. + +#### typedarraypool.nbytes + +**Read-only** property returning the total number of allocated bytes. + +```javascript +var arr = typedarraypool( 5, 'float64' ); + +var nbytes = typedarraypool.nbytes; +// returns +``` + +The returned value is the total **accumulated** value. Hence, anytime a pool must allocate a new [array buffer][mdn-arraybuffer] (i.e., more memory), the pool increments this value. The only time this value is decremented is when a pool is cleared. This behavior means that, while allocated buffers which are never freed may, in fact, be garbage collected, they continue to count against the high water mark limit. Accordingly, you should **always** free allocated buffers in order to prevent the pool from believing that non-freed buffers are continually in use. + +#### typedarraypool.factory( \[options] ) + +Creates a new [typed array][mdn-typed-array] pool. + +```javascript +var pool = typedarraypool.factory(); + +var arr = pool( 5, 'float64' ); +// returns + +// ... + +pool.free( arr ); +``` + +The method accepts the following `options`: + +- **highWaterMark**: maximum total memory (in bytes) which can be allocated. Default: `2^53` bytes. + +By default, the maximum total memory a pool may allocate is `2^53` bytes (approximately `1` petabyte, which, in practical terms, means a pool has **unlimited** capacity). To specify an alternative limit, set the `highWaterMark` option. + +```javascript +// Create a new typed array pool which can allocate up to 1MB: +var pool = typedarraypool.factory({ + 'highWaterMark': 1e6 +}); + +var arr = pool( 5, 'float64' ); +// returns + +// ... + +pool.free( arr ); +``` + +
+ + + + + +
+ +## Notes + +- Uninitialized typed arrays may contain sensitive contents. If security is paramount (e.g., if freed [typed arrays][mdn-typed-array] have been used to store sensitive contents), use `calloc`. +- An allocated [typed array][mdn-typed-array] is **guaranteed** to have an underlying [array buffer][mdn-arraybuffer] with _at least_ `N * w` bytes, where `N` is the number of [typed array][mdn-typed-array] elements and `w` is the number of bytes per element. Note, however, that the underlying [array buffer][mdn-arraybuffer] is likely to have **excess** capacity. Thus, if you create many [typed arrays][mdn-typed-array] which are held in memory and are **not** freed, you are likely to consume significantly more memory than if you had directly used [typed array][mdn-typed-array] constructors. However, if you create many [typed arrays][mdn-typed-array] which are rapidly discarded and of relatively large size, then using a [typed array][mdn-typed-array] pool can offer significant performance advantages. + +
+ + + + + +
+ +## 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..4500b91 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,359 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2021 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 2.0 + +/// + +import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; +import ArrayBuffer = require( '@stdlib/array-buffer' ); + +/** +* Typed array or null. +*/ +type TypedArrayOrNull = RealOrComplexTypedArray | null; + +/** +* Interface defining pool options. +*/ +interface Options { + /** + * Maximum total memory which can be allocated. + */ + highWaterMark?: number; +} + +/** +* Pool interface. +*/ +interface Pool { + /** + * Returns an uninitialized typed array. + * + * ## Notes + * + * - Memory is **not** initialized. + * - Memory is lazily allocated. + * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). + * + * @param dtype - data type (default: 'float64') + * @returns typed array or null + * + * @example + * var arr = typedarraypool(); + * // returns [] + * + * @example + * var arr = typedarraypool( 'float32' ); + * // returns [] + */ + ( dtype?: DataType ): TypedArrayOrNull; + + /** + * Returns an uninitialized typed array. + * + * ## Notes + * + * - Memory is **not** initialized. + * - Memory is lazily allocated. + * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). + * + * @param arg - an array length or an array-like object + * @param dtype - data type (default: 'float64') + * @returns typed array or null + * + * @example + * // Allocate an array of doubles: + * var arr = typedarraypool( 5, 'float64' ); + * // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] + * + * arr[ 0 ] = 3.14; + * arr[ 1 ] = 3.14; + * + * // ... + * + * // Free the allocated memory to be used in a future allocation: + * typedarraypool.free( arr ); + * + * @example + * var arr1 = typedarraypool( [ 0.5, 0.5, 0.5 ] ); + * var arr2 = typedarraypool( arr1, 'float32' ); + * // returns [ 0.5, 0.5, 0.5 ] + * + * @example + * var arr1 = [ 0.5, 0.5, 0.5 ]; + * var arr2 = typedarraypool( arr1, 'float32' ); + * // returns [ 0.5, 0.5, 0.5 ] + */ + ( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; + + /** + * Returns a zero-initialized typed array. + * + * ## Notes + * + * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). + * + * @param dtype - data type (default: 'float64') + * @returns typed array or null + * + * @example + * var arr1 = typedarraypool.calloc(); + * // returns [] + * + * var arr2 = typedarraypool.calloc( 'int32' ); + * // returns [] + * + * // ... + * + * typedarraypool.free( arr1 ); + * typedarraypool.free( arr2 ); + */ + calloc( dtype?: DataType ): TypedArrayOrNull; + + /** + * Returns a zero-initialized typed array. + * + * ## Notes + * + * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). + * + * @param length - typed array length + * @param dtype - data type (default: 'float64') + * @returns typed array or null + * + * @example + * var arr1 = typedarraypool.calloc( 5 ); + * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] + * + * var arr2 = typedarraypool.calloc( 5, 'uint8' ); + * // returns [ 0, 0, 0, 0, 0 ] + * + * // ... + * + * typedarraypool.free( arr1 ); + * typedarraypool.free( arr2 ); + */ + calloc( length: number, dtype?: DataType ): TypedArrayOrNull; + + /** + * Returns an uninitialized typed array. + * + * ## Notes + * + * - Memory is **not** initialized. + * - Memory is lazily allocated. + * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). + * + * @param dtype - data type (default: 'float64') + * @returns typed array or null + * + * @example + * var arr1 = typedarraypool.malloc(); + * // returns [] + * + * var arr2 = typedarraypool.malloc( 'int32' ); + * // returns [] + * + * // ... + * + * typedarraypool.free( arr1 ); + * typedarraypool.free( arr2 ); + */ + malloc( dtype?: DataType ): TypedArrayOrNull; + + /** + * Returns an uninitialized typed array. + * + * ## Notes + * + * - Memory is **not** initialized. + * - Memory is lazily allocated. + * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). + * + * @param arg - an array length or an array-like object + * @param dtype - data type (default: 'float64') + * @returns typed array or null + * + * @example + * var arr1 = typedarraypool.malloc( 5 ); + * // returns + * + * var arr2 = typedarraypool.malloc( 5, 'uint8' ); + * // returns + * + * // ... + * + * typedarraypool.free( arr1 ); + * typedarraypool.free( arr2 ); + * + * @example + * var arr1 = typedarraypool.malloc( [ 5.0, -3.0, 2.0 ] ); + * // returns [ 5.0, -3.0, 2.0 ] + * + * var arr2 = typedarraypool.malloc( arr1 ); + * // returns [ 5.0, -3.0, 2.0 ] + * + * var arr3 = typedarraypool.malloc( arr1, 'int32' ); + * // returns [ 5, -3, 2 ] + * + * // ... + * + * typedarraypool.free( arr1 ); + * typedarraypool.free( arr2 ); + * typedarraypool.free( arr3 ); + * + * @example + * var arr1 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ] ); + * // returns [ 0.5, 0.5, 0.5 ] + * + * var arr2 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ], 'float32' ); + * // returns [ 0.5, 0.5, 0.5 ] + * + * // ... + * + * typedarraypool.free( arr1 ); + * typedarraypool.free( arr2 ); + */ + malloc( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; + + /** + * Frees a typed array or typed array buffer for use in a future allocation. + * + * @param buf - typed array or typed array buffer to free + * + * @example + * var arr = typedarraypool( 10, 'float64' ); + * // returns + * + * // ... + * + * // Free the allocated typed array for use in a future allocation: + * typedarraypool.free( arr ); + * + * // Create another typed array: + * arr = typedarraypool( 10, 'float64' ); + * // returns + * + * // ... + * + * // Free the allocated typed array buffer for use in a future allocation: + * typedarraypool.free( arr.buffer ); + */ + free( buf: RealOrComplexTypedArray | ArrayBuffer ): void; + + /** + * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. + * + * @example + * var arr = typedarraypool( 10, 'float64' ); + * // returns + * + * // ... + * + * typedarraypool.free( arr ); + * + * // ... + * + * // Clear all freed buffers: + * typedarraypool.clear(); + */ + clear(): void; + + /** + * Read-only property returning the pool's high water mark. + * + * ## Notes + * + * - Once a high water mark is reached, typed array allocation fails. + * + * @example + * var limit = typedarraypool.highWaterMark; + * // returns + */ + readonly highWaterMark: number; + + /** + * Read-only property returning the total number of allocated bytes. + * + * @example + * var arr = typedarraypool( 5, 'float64' ); + * + * var nbytes = typedarraypool.nbytes; + * // returns + */ + readonly nbytes: number; + + /** + * Creates a typed array pool. + * + * @param options - pool options + * @param options.highWaterMark - maximum total memory which can be allocated + * @throws must provide valid options + * @returns allocator + * + * @example + * var allocator = typedarraypool.factory(); + * + * // Allocate an array of doubles: + * var arr = allocator( 5, 'float64' ); + * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] + * + * arr[ 0 ] = 3.14; + * arr[ 1 ] = 3.14; + * + * // ... + * + * // Free the allocated memory to be used in a future allocation: + * allocator.free( arr ); + */ + factory( options?: Options ): Pool; +} + +/** +* Returns an uninitialized typed array. +* +* ## Notes +* +* - Memory is **not** initialized. +* - Memory is lazily allocated. +* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). +* +* @param arg - an array length or an array-like object +* @param dtype - data type (default: 'float64') +* @returns typed array or null +* +* @example +* // Allocate an array of doubles: +* var arr = typedarraypool( 5, 'float64' ); +* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] +* +* arr[ 0 ] = 3.14; +* arr[ 1 ] = 3.14; +* +* // ... +* +* // Free the allocated memory to be used in a future allocation: +* typedarraypool.free( arr ); +*/ +declare var typedarraypool: Pool; + + +// EXPORTS // + +export = typedarraypool; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9c033f5 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";var w={highWaterMark:9007199254740992},M=y,W=k,E=r.isPrimitive,T=f;var V=function(e,t){return M(t)?W(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!E(e.highWaterMark))?new TypeError(T("invalid option. `%s` option must be a nonnegative integer. Option: `%s`.","highWaterMark",e.highWaterMark)):null:new TypeError(T("invalid argument. Options argument must be an object. Value: `%s`.",t))};var P=function(e){var t,r;for(t=[],r=0;rs.highWaterMark?null:(i=new R(e),t+=e,i)}function o(e,t,r){var s;return 0===t?new e(0):null===(s=a(X(t)*te[r]))?s:new e(s,0,t)}function m(){var e,t,r,s,i,n,a,m,l;if(t=(e=arguments.length)&&O(arguments[e-1])?arguments[e-=1]:"float64",null===(r=H(t)))throw new TypeError(N("invalid argument. Must provide a recognized data type. Value: `%s`.",t));if(e<=0)return new r(0);if(z(arguments[0]))return o(r,arguments[0],t);if(F(arguments[0])){if(m=(s=arguments[0]).length,C(s)?s=J(s,0):B(s)?s=I(s,0):/^complex/.test(t)&&(m/=2),null===(i=o(r,m,t)))return i;if(ne(i)||ie(i))return i.set(s),i;for(a=K(s).getter,n=K(i).setter,l=0;l0){for(t=U(Y(e.byteLength)),t=Z(r.length-1,t),s=r[t],i=0;i[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = copy( defaults );\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring user's don't do ill-advised things...\n\t\t\tget = arraylike2object( arr ).getter;\n\t\t\tset = arraylike2object( out ).setter;\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or typed array buffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* var typedarraypool = require( '@stdlib/array-pool' );\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nmodule.exports = typedarraypool;\n"],"names":["isObject","require$$0","hasOwnProp","require$$1","isNonNegativeInteger","require$$2","isPrimitive","format","require$$3","validate_1","opts","options","highWaterMark","TypeError","pool_1","n","out","i","push","isString","isCollection","isTypedArrayLike","isArrayBuffer","require$$4","isComplex64Array","require$$5","isComplex128Array","require$$6","setReadOnly","require$$7","setReadOnlyAccessor","require$$8","ctors","require$$9","reinterpret64","require$$10","reinterpret128","require$$11","arraylike2object","require$$12","require$$13","copy","require$$14","ArrayBuffer","require$$15","ceil","require$$16","floor","require$$17","ceil2","require$$18","log2","require$$19","min","require$$20","defaults","require$$21","validate","require$$22","createPool","require$$23","BYTES_PER_ELEMENT","require$$24","Complex64Array","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory_1","nbytes","pool","err","arguments","length","malloc","calloc","free","clear","getBytes","arraybuffer","buf","pop","typedarray","ctor","len","dtype","nargs","set","get","test","getter","setter","tmp","p","buffer","byteLength","main","factory","lib"],"mappings":";;8mEAsBIA,EAAWC,EACXC,EAAaC,EACbC,EAAuBC,EAAmDC,YAC1EC,EAASC,EAwCb,IAAAC,EAhBA,SAAmBC,EAAMC,GACxB,OAAMX,EAAUW,GAGXT,EAAYS,EAAS,mBACzBD,EAAKE,cAAgBD,EAAQC,eACvBR,EAAsBM,EAAKE,gBACzB,IAAIC,UAAWN,EAAQ,2EAA4E,gBAAiBG,EAAKE,gBAG3H,KARC,IAAIC,UAAWN,EAAQ,qEAAsEI,KCRtG,IAAAG,EAdA,SAAeC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,+GCfJG,EAAWlB,EAAsCK,YACjDF,EAAuBD,EAAmDG,YAC1Ec,EAAef,EACfgB,EAAmBb,EACnBc,EAAgBC,EAChBC,EAAmBC,EACnBC,EAAoBC,EACpBC,EAAcC,EACdC,EAAsBC,EACtBC,EAAQC,EACRC,EAAgBC,EAChBC,EAAiBC,EACjBC,EAAmBC,EACnBhC,EAASiC,EACTC,EAAOC,EACPC,EAAcC,EACdC,EAAOC,EACPC,EAAQC,EACRC,EAAQC,EACRC,EAAOC,EACPC,EAAMC,EACNC,EAAWC,EACXC,EAAWC,EACXC,GAAaC,EACbC,GAAoBC,EAKpBC,GAAiB/B,EAAO,aACxBgC,GAAkBhC,EAAO,cAY7B,SAASiC,GAAgBC,GACxB,OAASA,aAAeH,GAUzB,SAASI,GAAiBD,GACzB,OAASA,aAAeF,GAqSzB,IAAAI,GAvQA,SAAkBzD,GACjB,IAAI0D,EACAC,EACA5D,EACA6D,EAGJ,GADA7D,EAAO+B,EAAMc,GACRiB,UAAUC,SACdF,EAAMd,EAAU/C,EAAMC,IAErB,MAAM4D,EAaR,OAVAD,EAAOX,GAAYd,EAAMM,EAAMzC,EAAKE,iBACpCyD,EAAS,EAETzC,EAAa8C,EAAQ,SAAUA,GAC/B9C,EAAa8C,EAAQ,SAAUC,GAC/B/C,EAAa8C,EAAQ,OAAQE,GAC7BhD,EAAa8C,EAAQ,QAASG,GAC9BjD,EAAa8C,EAAQ,gBAAiBhE,EAAKE,eAC3CkB,EAAqB4C,EAAQ,SAAUI,GAEhCJ,EAQP,SAASI,IACR,OAAOT,EAUR,SAASU,EAAahE,GACrB,IAAIiE,EACA/D,EAMJ,OAHAA,EAAIkC,EAAMpC,IAGDuD,EAAKG,QAAUH,EAAMrD,GAAIwD,OAC1BH,EAAMrD,GAAIgE,MAGbZ,EAAOtD,EAAIL,EAAKE,cACb,MAERoE,EAAM,IAAIrC,EAAa5B,GAGvBsD,GAAUtD,EAEHiE,GAYR,SAASE,EAAYC,EAAMC,EAAKC,GAC/B,IAAIL,EACJ,OAAa,IAARI,EACG,IAAID,EAAM,GAGL,QADbH,EAAMD,EAAa9B,EAAOmC,GAAMvB,GAAmBwB,KAE3CL,EAED,IAAIG,EAAMH,EAAK,EAAGI,GAmB1B,SAASV,IACR,IAAIY,EACAD,EACAF,EACAjB,EACAlD,EACAuE,EACAC,EACAJ,EACAnE,EAUJ,GALCoE,GAHDC,EAAQd,UAAUC,SACJtD,EAAUqD,UAAWc,EAAM,IAEhCd,UADRc,GAAS,GAGD,UAGK,QADdH,EAAOnD,EAAOqD,IAEb,MAAM,IAAIxE,UAAWN,EAAQ,sEAAuE8E,IAErG,GAAKC,GAAS,EACb,OAAO,IAAIH,EAAM,GAGlB,GAAK/E,EAAsBoE,UAAW,IACrC,OAAOU,EAAYC,EAAMX,UAAW,GAAKa,GAG1C,GAAKjE,EAAcoD,UAAW,IAAQ,CAYrC,GAVAY,GADAlB,EAAMM,UAAW,IACPC,OACL/C,EAAmBwC,GACvBA,EAAM9B,EAAgB8B,EAAK,GAChB1C,EAAkB0C,GAC7BA,EAAMhC,EAAegC,EAAK,GACf,WAAWuB,KAAMJ,KAE5BD,GAAO,GAGK,QADbpE,EAAMkE,EAAYC,EAAMC,EAAKC,IAE5B,OAAOrE,EAER,GAAKmD,GAAiBnD,IAASiD,GAAgBjD,GAE9C,OADAA,EAAIuE,IAAKrB,GACFlD,EAKR,IAFAwE,EAAMlD,EAAkB4B,GAAMwB,OAC9BH,EAAMjD,EAAkBtB,GAAM2E,OACxB1E,EAAI,EAAGA,EAAImE,EAAKnE,IACrBsE,EAAKvE,EAAKC,EAAGuE,EAAKtB,EAAKjD,IAExB,OAAOD,EAER,MAAM,IAAIH,UAAWN,EAAQ,wGAAyGiE,UAAW,KAiBlJ,SAASG,IACR,IAAIW,EACAtE,EACA4E,EACA3E,EAUJ,GAAa,QANZD,EADc,KADfsE,EAAQd,UAAUC,QAEXC,IACe,IAAVY,EACLZ,EAAQF,UAAW,IAEnBE,EAAQF,UAAW,GAAKA,UAAW,KAWzC,IANCoB,EADIzB,GAAiBnD,GACfoB,EAAgBpB,EAAK,GAChBiD,GAAgBjD,GACrBkB,EAAelB,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAI2E,EAAInB,OAAQxD,IAC5B2E,EAAK3E,GAAM,EAGb,OAAOD,EAeR,SAAS4D,EAAMI,GACd,IAAIjE,EACA8E,EACA5E,EACJ,GAAKI,EAAkB2D,IAASA,EAAIc,OACnCd,EAAMA,EAAIc,YACJ,IAAMxE,EAAe0D,GAC3B,MAAM,IAAInE,UAAWN,EAAQ,mFAAoFyE,IAElH,GAAKA,EAAIe,WAAa,EAAI,CAQzB,IAPAhF,EAAIgC,EAAOI,EAAM6B,EAAIe,aAGrBhF,EAAIsC,EAAKiB,EAAKG,OAAO,EAAG1D,GAGxB8E,EAAIvB,EAAMvD,GACJE,EAAI,EAAGA,EAAI4E,EAAEpB,OAAQxD,IAC1B,GAAK4E,EAAG5E,KAAQ+D,EACf,OAAO,EAITa,EAAE3E,KAAM8D,GAET,OAAO,EAQR,SAASH,IACR,IAAI5D,EACJ,IAAMA,EAAI,EAAGA,EAAIqD,EAAKG,OAAQxD,IAC7BqD,EAAMrD,GAAIwD,OAAS,EAEpBJ,EAAS,IC9TX2B,GCtBc/F,KDuBdgG,GAAA5F,GAFAJ,EAOA+F,GAAA,UAAAC,IAKA,IAAAC,GAAAF"} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..527a858 --- /dev/null +++ b/package.json @@ -0,0 +1,73 @@ +{ + "name": "@stdlib/array-pool", + "version": "0.0.0", + "description": "Typed array pool.", + "license": "Apache-2.0", + "type": "module", + "main": "./index.mjs", + "homepage": "https://stdlib.io", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/array-pool.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "keywords": [ + "stdlib", + "stdtypes", + "types", + "data", + "structure", + "typed", + "array", + "typed array", + "typed-array", + "vector", + "ndarray", + "matrix", + "float64array", + "float32array", + "int32array", + "uint32array", + "int16array", + "uint16array", + "int8array", + "uint8array", + "uint8clampedarray", + "complex64array", + "complex128array", + "float64", + "double", + "precision", + "double-precision", + "single", + "float", + "single-precision", + "float32", + "ieee754", + "integer", + "int32", + "signed", + "unsigned", + "uint32", + "int16", + "uint16", + "int8", + "uint8", + "uint8c", + "complex64", + "complex128", + "complex", + "clamped", + "short", + "long", + "pool", + "memory", + "mem" + ], + "funding": { + "type": "patreon", + "url": "https://www.patreon.com/athan" + } +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..67c4d8b --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + From 0243fd11cefc3bf0d33c40ad45aff8de7fb4413b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 30 Jun 2022 22:54:28 +0000 Subject: [PATCH 002/103] Transform error messages --- lib/factory.js | 6 +++--- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 2401100..b75e403 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -33,7 +33,7 @@ var ctors = require( '@stdlib/array-typed-ctors' ); var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( '@stdlib/utils-copy' ); var ArrayBuffer = require( '@stdlib/array-buffer' ); var ceil = require( '@stdlib/math-base-special-ceil' ); @@ -226,7 +226,7 @@ function factory( options ) { } ctor = ctors( dtype ); if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '00d2k', dtype ) ); } if ( nargs <= 0 ) { return new ctor( 0 ); @@ -263,7 +263,7 @@ function factory( options ) { } return out; } - throw new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) ); + throw new TypeError( format( '00d33', arguments[ 0 ] ) ); } /** diff --git a/lib/validate.js b/lib/validate.js index ce54890..4135ec9 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '00d2h', options ) ); } if ( hasOwnProp( options, 'highWaterMark' ) ) { opts.highWaterMark = options.highWaterMark; if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) ); + return new TypeError( format( '00d35', 'highWaterMark', opts.highWaterMark ) ); } } return null; diff --git a/package.json b/package.json index 50986ed..558fca7 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "@stdlib/math-base-special-min": "^0.0.x", "@stdlib/strided-base-reinterpret-complex128": "^0.0.x", "@stdlib/strided-base-reinterpret-complex64": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-copy": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", From 544b573cf63829dd85a941a6ca10a8a474100733 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 07:10:26 +0000 Subject: [PATCH 003/103] Remove files --- index.d.ts | 359 ------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 3053 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 4500b91..0000000 --- a/index.d.ts +++ /dev/null @@ -1,359 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; -import ArrayBuffer = require( '@stdlib/array-buffer' ); - -/** -* Typed array or null. -*/ -type TypedArrayOrNull = RealOrComplexTypedArray | null; - -/** -* Interface defining pool options. -*/ -interface Options { - /** - * Maximum total memory which can be allocated. - */ - highWaterMark?: number; -} - -/** -* Pool interface. -*/ -interface Pool { - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr = typedarraypool(); - * // returns [] - * - * @example - * var arr = typedarraypool( 'float32' ); - * // returns [] - */ - ( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * // Allocate an array of doubles: - * var arr = typedarraypool( 5, 'float64' ); - * // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * typedarraypool.free( arr ); - * - * @example - * var arr1 = typedarraypool( [ 0.5, 0.5, 0.5 ] ); - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * @example - * var arr1 = [ 0.5, 0.5, 0.5 ]; - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - */ - ( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc(); - * // returns [] - * - * var arr2 = typedarraypool.calloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param length - typed array length - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc( 5 ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * var arr2 = typedarraypool.calloc( 5, 'uint8' ); - * // returns [ 0, 0, 0, 0, 0 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( length: number, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc(); - * // returns [] - * - * var arr2 = typedarraypool.malloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc( 5 ); - * // returns - * - * var arr2 = typedarraypool.malloc( 5, 'uint8' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 5.0, -3.0, 2.0 ] ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr2 = typedarraypool.malloc( arr1 ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr3 = typedarraypool.malloc( arr1, 'int32' ); - * // returns [ 5, -3, 2 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * typedarraypool.free( arr3 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ] ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * var arr2 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ], 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Frees a typed array or typed array buffer for use in a future allocation. - * - * @param buf - typed array or typed array buffer to free - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array for use in a future allocation: - * typedarraypool.free( arr ); - * - * // Create another typed array: - * arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array buffer for use in a future allocation: - * typedarraypool.free( arr.buffer ); - */ - free( buf: RealOrComplexTypedArray | ArrayBuffer ): void; - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr ); - * - * // ... - * - * // Clear all freed buffers: - * typedarraypool.clear(); - */ - clear(): void; - - /** - * Read-only property returning the pool's high water mark. - * - * ## Notes - * - * - Once a high water mark is reached, typed array allocation fails. - * - * @example - * var limit = typedarraypool.highWaterMark; - * // returns - */ - readonly highWaterMark: number; - - /** - * Read-only property returning the total number of allocated bytes. - * - * @example - * var arr = typedarraypool( 5, 'float64' ); - * - * var nbytes = typedarraypool.nbytes; - * // returns - */ - readonly nbytes: number; - - /** - * Creates a typed array pool. - * - * @param options - pool options - * @param options.highWaterMark - maximum total memory which can be allocated - * @throws must provide valid options - * @returns allocator - * - * @example - * var allocator = typedarraypool.factory(); - * - * // Allocate an array of doubles: - * var arr = allocator( 5, 'float64' ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * allocator.free( arr ); - */ - factory( options?: Options ): Pool; -} - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @param arg - an array length or an array-like object -* @param dtype - data type (default: 'float64') -* @returns typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -declare var typedarraypool: Pool; - - -// EXPORTS // - -export = typedarraypool; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9c033f5..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";var w={highWaterMark:9007199254740992},M=y,W=k,E=r.isPrimitive,T=f;var V=function(e,t){return M(t)?W(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!E(e.highWaterMark))?new TypeError(T("invalid option. `%s` option must be a nonnegative integer. Option: `%s`.","highWaterMark",e.highWaterMark)):null:new TypeError(T("invalid argument. Options argument must be an object. Value: `%s`.",t))};var P=function(e){var t,r;for(t=[],r=0;rs.highWaterMark?null:(i=new R(e),t+=e,i)}function o(e,t,r){var s;return 0===t?new e(0):null===(s=a(X(t)*te[r]))?s:new e(s,0,t)}function m(){var e,t,r,s,i,n,a,m,l;if(t=(e=arguments.length)&&O(arguments[e-1])?arguments[e-=1]:"float64",null===(r=H(t)))throw new TypeError(N("invalid argument. Must provide a recognized data type. Value: `%s`.",t));if(e<=0)return new r(0);if(z(arguments[0]))return o(r,arguments[0],t);if(F(arguments[0])){if(m=(s=arguments[0]).length,C(s)?s=J(s,0):B(s)?s=I(s,0):/^complex/.test(t)&&(m/=2),null===(i=o(r,m,t)))return i;if(ne(i)||ie(i))return i.set(s),i;for(a=K(s).getter,n=K(i).setter,l=0;l0){for(t=U(Y(e.byteLength)),t=Z(r.length-1,t),s=r[t],i=0;i[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = copy( defaults );\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring user's don't do ill-advised things...\n\t\t\tget = arraylike2object( arr ).getter;\n\t\t\tset = arraylike2object( out ).setter;\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or typed array buffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* var typedarraypool = require( '@stdlib/array-pool' );\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nmodule.exports = typedarraypool;\n"],"names":["isObject","require$$0","hasOwnProp","require$$1","isNonNegativeInteger","require$$2","isPrimitive","format","require$$3","validate_1","opts","options","highWaterMark","TypeError","pool_1","n","out","i","push","isString","isCollection","isTypedArrayLike","isArrayBuffer","require$$4","isComplex64Array","require$$5","isComplex128Array","require$$6","setReadOnly","require$$7","setReadOnlyAccessor","require$$8","ctors","require$$9","reinterpret64","require$$10","reinterpret128","require$$11","arraylike2object","require$$12","require$$13","copy","require$$14","ArrayBuffer","require$$15","ceil","require$$16","floor","require$$17","ceil2","require$$18","log2","require$$19","min","require$$20","defaults","require$$21","validate","require$$22","createPool","require$$23","BYTES_PER_ELEMENT","require$$24","Complex64Array","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory_1","nbytes","pool","err","arguments","length","malloc","calloc","free","clear","getBytes","arraybuffer","buf","pop","typedarray","ctor","len","dtype","nargs","set","get","test","getter","setter","tmp","p","buffer","byteLength","main","factory","lib"],"mappings":";;8mEAsBIA,EAAWC,EACXC,EAAaC,EACbC,EAAuBC,EAAmDC,YAC1EC,EAASC,EAwCb,IAAAC,EAhBA,SAAmBC,EAAMC,GACxB,OAAMX,EAAUW,GAGXT,EAAYS,EAAS,mBACzBD,EAAKE,cAAgBD,EAAQC,eACvBR,EAAsBM,EAAKE,gBACzB,IAAIC,UAAWN,EAAQ,2EAA4E,gBAAiBG,EAAKE,gBAG3H,KARC,IAAIC,UAAWN,EAAQ,qEAAsEI,KCRtG,IAAAG,EAdA,SAAeC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,+GCfJG,EAAWlB,EAAsCK,YACjDF,EAAuBD,EAAmDG,YAC1Ec,EAAef,EACfgB,EAAmBb,EACnBc,EAAgBC,EAChBC,EAAmBC,EACnBC,EAAoBC,EACpBC,EAAcC,EACdC,EAAsBC,EACtBC,EAAQC,EACRC,EAAgBC,EAChBC,EAAiBC,EACjBC,EAAmBC,EACnBhC,EAASiC,EACTC,EAAOC,EACPC,EAAcC,EACdC,EAAOC,EACPC,EAAQC,EACRC,EAAQC,EACRC,EAAOC,EACPC,EAAMC,EACNC,EAAWC,EACXC,EAAWC,EACXC,GAAaC,EACbC,GAAoBC,EAKpBC,GAAiB/B,EAAO,aACxBgC,GAAkBhC,EAAO,cAY7B,SAASiC,GAAgBC,GACxB,OAASA,aAAeH,GAUzB,SAASI,GAAiBD,GACzB,OAASA,aAAeF,GAqSzB,IAAAI,GAvQA,SAAkBzD,GACjB,IAAI0D,EACAC,EACA5D,EACA6D,EAGJ,GADA7D,EAAO+B,EAAMc,GACRiB,UAAUC,SACdF,EAAMd,EAAU/C,EAAMC,IAErB,MAAM4D,EAaR,OAVAD,EAAOX,GAAYd,EAAMM,EAAMzC,EAAKE,iBACpCyD,EAAS,EAETzC,EAAa8C,EAAQ,SAAUA,GAC/B9C,EAAa8C,EAAQ,SAAUC,GAC/B/C,EAAa8C,EAAQ,OAAQE,GAC7BhD,EAAa8C,EAAQ,QAASG,GAC9BjD,EAAa8C,EAAQ,gBAAiBhE,EAAKE,eAC3CkB,EAAqB4C,EAAQ,SAAUI,GAEhCJ,EAQP,SAASI,IACR,OAAOT,EAUR,SAASU,EAAahE,GACrB,IAAIiE,EACA/D,EAMJ,OAHAA,EAAIkC,EAAMpC,IAGDuD,EAAKG,QAAUH,EAAMrD,GAAIwD,OAC1BH,EAAMrD,GAAIgE,MAGbZ,EAAOtD,EAAIL,EAAKE,cACb,MAERoE,EAAM,IAAIrC,EAAa5B,GAGvBsD,GAAUtD,EAEHiE,GAYR,SAASE,EAAYC,EAAMC,EAAKC,GAC/B,IAAIL,EACJ,OAAa,IAARI,EACG,IAAID,EAAM,GAGL,QADbH,EAAMD,EAAa9B,EAAOmC,GAAMvB,GAAmBwB,KAE3CL,EAED,IAAIG,EAAMH,EAAK,EAAGI,GAmB1B,SAASV,IACR,IAAIY,EACAD,EACAF,EACAjB,EACAlD,EACAuE,EACAC,EACAJ,EACAnE,EAUJ,GALCoE,GAHDC,EAAQd,UAAUC,SACJtD,EAAUqD,UAAWc,EAAM,IAEhCd,UADRc,GAAS,GAGD,UAGK,QADdH,EAAOnD,EAAOqD,IAEb,MAAM,IAAIxE,UAAWN,EAAQ,sEAAuE8E,IAErG,GAAKC,GAAS,EACb,OAAO,IAAIH,EAAM,GAGlB,GAAK/E,EAAsBoE,UAAW,IACrC,OAAOU,EAAYC,EAAMX,UAAW,GAAKa,GAG1C,GAAKjE,EAAcoD,UAAW,IAAQ,CAYrC,GAVAY,GADAlB,EAAMM,UAAW,IACPC,OACL/C,EAAmBwC,GACvBA,EAAM9B,EAAgB8B,EAAK,GAChB1C,EAAkB0C,GAC7BA,EAAMhC,EAAegC,EAAK,GACf,WAAWuB,KAAMJ,KAE5BD,GAAO,GAGK,QADbpE,EAAMkE,EAAYC,EAAMC,EAAKC,IAE5B,OAAOrE,EAER,GAAKmD,GAAiBnD,IAASiD,GAAgBjD,GAE9C,OADAA,EAAIuE,IAAKrB,GACFlD,EAKR,IAFAwE,EAAMlD,EAAkB4B,GAAMwB,OAC9BH,EAAMjD,EAAkBtB,GAAM2E,OACxB1E,EAAI,EAAGA,EAAImE,EAAKnE,IACrBsE,EAAKvE,EAAKC,EAAGuE,EAAKtB,EAAKjD,IAExB,OAAOD,EAER,MAAM,IAAIH,UAAWN,EAAQ,wGAAyGiE,UAAW,KAiBlJ,SAASG,IACR,IAAIW,EACAtE,EACA4E,EACA3E,EAUJ,GAAa,QANZD,EADc,KADfsE,EAAQd,UAAUC,QAEXC,IACe,IAAVY,EACLZ,EAAQF,UAAW,IAEnBE,EAAQF,UAAW,GAAKA,UAAW,KAWzC,IANCoB,EADIzB,GAAiBnD,GACfoB,EAAgBpB,EAAK,GAChBiD,GAAgBjD,GACrBkB,EAAelB,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAI2E,EAAInB,OAAQxD,IAC5B2E,EAAK3E,GAAM,EAGb,OAAOD,EAeR,SAAS4D,EAAMI,GACd,IAAIjE,EACA8E,EACA5E,EACJ,GAAKI,EAAkB2D,IAASA,EAAIc,OACnCd,EAAMA,EAAIc,YACJ,IAAMxE,EAAe0D,GAC3B,MAAM,IAAInE,UAAWN,EAAQ,mFAAoFyE,IAElH,GAAKA,EAAIe,WAAa,EAAI,CAQzB,IAPAhF,EAAIgC,EAAOI,EAAM6B,EAAIe,aAGrBhF,EAAIsC,EAAKiB,EAAKG,OAAO,EAAG1D,GAGxB8E,EAAIvB,EAAMvD,GACJE,EAAI,EAAGA,EAAI4E,EAAEpB,OAAQxD,IAC1B,GAAK4E,EAAG5E,KAAQ+D,EACf,OAAO,EAITa,EAAE3E,KAAM8D,GAET,OAAO,EAQR,SAASH,IACR,IAAI5D,EACJ,IAAMA,EAAI,EAAGA,EAAIqD,EAAKG,OAAQxD,IAC7BqD,EAAMrD,GAAIwD,OAAS,EAEpBJ,EAAS,IC9TX2B,GCtBc/F,KDuBdgG,GAAA5F,GAFAJ,EAOA+F,GAAA,UAAAC,IAKA,IAAAC,GAAAF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 67c4d8b..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From cb723b1f0b12c785237250869b554cfa8f52711d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 07:11:20 +0000 Subject: [PATCH 004/103] 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 | 43 +- benchmark/benchmark.calloc.js | 246 -- benchmark/benchmark.factory.js | 71 - benchmark/benchmark.js | 246 -- benchmark/benchmark.length.complex128.js | 102 - benchmark/benchmark.length.complex64.js | 102 - benchmark/benchmark.length.float32.js | 102 - benchmark/benchmark.length.float64.js | 102 - benchmark/benchmark.length.int16.js | 102 - benchmark/benchmark.length.int32.js | 102 - benchmark/benchmark.length.int8.js | 102 - benchmark/benchmark.length.uint16.js | 102 - benchmark/benchmark.length.uint32.js | 102 - benchmark/benchmark.length.uint8.js | 102 - benchmark/benchmark.length.uint8c.js | 102 - benchmark/benchmark.malloc.js | 246 -- branches.md | 53 - docs/repl.txt | 347 --- docs/types/test.ts | 193 -- examples/index.js | 80 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/bytes_per_element.json | 13 - lib/defaults.json | 3 - lib/factory.js | 370 --- lib/index.js | 56 - lib/main.js | 63 - lib/pool.js | 44 - lib/validate.js | 66 - package.json | 97 +- stats.html | 2689 +++++++++++++++++++++ test/test.factory.js | 2240 ----------------- test/test.js | 1797 -------------- 57 files changed, 2718 insertions(+), 10223 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.calloc.js delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.complex128.js delete mode 100644 benchmark/benchmark.length.complex64.js delete mode 100644 benchmark/benchmark.length.float32.js delete mode 100644 benchmark/benchmark.length.float64.js delete mode 100644 benchmark/benchmark.length.int16.js delete mode 100644 benchmark/benchmark.length.int32.js delete mode 100644 benchmark/benchmark.length.int8.js delete mode 100644 benchmark/benchmark.length.uint16.js delete mode 100644 benchmark/benchmark.length.uint32.js delete mode 100644 benchmark/benchmark.length.uint8.js delete mode 100644 benchmark/benchmark.length.uint8c.js delete mode 100644 benchmark/benchmark.malloc.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/bytes_per_element.json delete mode 100644 lib/defaults.json delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/pool.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 12e5f5b..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-06-30T22:53:46.595Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ea35f20..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/array/pool) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 fc6d38a..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/array/pool) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -482,7 +481,7 @@ console.log( 'nbytes: %d', typedarray.nbytes ); ## 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]. @@ -548,7 +547,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm diff --git a/benchmark/benchmark.calloc.js b/benchmark/benchmark.calloc.js deleted file mode 100644 index e5a1c77..0000000 --- a/benchmark/benchmark.calloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':calloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index f7cd676..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = typedarray.factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:highWaterMark', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'highWaterMark': 0 - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.highWaterMark = i; - f = typedarray.factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a023d2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.complex128.js b/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 47b623b..0000000 --- a/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex64.js b/benchmark/benchmark.length.complex64.js deleted file mode 100644 index 40a412b..0000000 --- a/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float32.js b/benchmark/benchmark.length.float32.js deleted file mode 100644 index 0227ed7..0000000 --- a/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float64.js b/benchmark/benchmark.length.float64.js deleted file mode 100644 index 2dbac1c..0000000 --- a/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int16.js b/benchmark/benchmark.length.int16.js deleted file mode 100644 index e2a8adc..0000000 --- a/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int32.js b/benchmark/benchmark.length.int32.js deleted file mode 100644 index e4df0aa..0000000 --- a/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int8.js b/benchmark/benchmark.length.int8.js deleted file mode 100644 index 7ceac11..0000000 --- a/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint16.js b/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 9a532b6..0000000 --- a/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint32.js b/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 98f2d7f..0000000 --- a/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8.js b/benchmark/benchmark.length.uint8.js deleted file mode 100644 index 8359249..0000000 --- a/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8c.js b/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index d47d023..0000000 --- a/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.malloc.js b/benchmark/benchmark.malloc.js deleted file mode 100644 index d4eea72..0000000 --- a/benchmark/benchmark.malloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':malloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 8fce14f..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/array/pool" -click B href "https://github.com/stdlib-js/array-pool/tree/main" -click C href "https://github.com/stdlib-js/array-pool/tree/production" -click D href "https://github.com/stdlib-js/array-pool/tree/esm" -click E href "https://github.com/stdlib-js/array-pool/tree/deno" -click F href "https://github.com/stdlib-js/array-pool/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/pool -[production-url]: https://github.com/stdlib-js/array-pool/tree/production -[deno-url]: https://github.com/stdlib-js/array-pool/tree/deno -[umd-url]: https://github.com/stdlib-js/array-pool/tree/umd -[esm-url]: https://github.com/stdlib-js/array-pool/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5244595..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,347 +0,0 @@ - -{{alias}}( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - Memory is **uninitialized**, which means that the contents of a returned - typed array may contain sensitive contents. - - The function supports the following data types: - - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - The default typed array data type is `float64`. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}() - [] - > arr = {{alias}}( 'float32' ) - [] - - -{{alias}}( length[, dtype] ) - Returns an uninitialized typed array having a specified length from a typed - array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > arr = {{alias}}( 5, 'int32' ) - - - -{{alias}}( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - This method shares the same security vulnerabilities mentioned above. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc() - - > arr = {{alias}}.malloc( 'float32' ) - - - -{{alias}}.malloc( length[, dtype] ) - Returns a typed array having a specified length from a typed array memory - pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc( 5 ) - - > arr = {{alias}}.malloc( 5, 'int32' ) - - - -{{alias}}.malloc( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}.malloc( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.calloc( [dtype] ) - Returns a zero-initialized typed array from a typed array memory pool. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc() - [] - > arr = {{alias}}.calloc( 'float32' ) - [] - - -{{alias}}.calloc( length[, dtype] ) - Returns a zero-initialized typed array having a specified length from a - typed array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}.calloc( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}.free( buf ) - Frees a typed array or typed array buffer for use in a future allocation. - - Parameters - ---------- - buf: TypedArray|ArrayBuffer - Typed array or typed array buffer to free. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ) - - -{{alias}}.clear() - Clears the typed array pool allowing garbage collection of previously - allocated (and currently free) array buffers. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - > {{alias}}.clear() - - -{{alias}}.highWaterMark - Read-only property returning the pool's high water mark. - - Once a high water mark is reached, typed array allocation fails. - - Examples - -------- - > {{alias}}.highWaterMark - - -{{alias}}.nbytes - Read-only property returning the total number of allocated bytes. - - The returned value is the total accumulated value. Hence, anytime a pool - must allocate a new array buffer (i.e., more memory), the pool increments - this value. - - The only time this value is decremented is when a pool is cleared. - - This behavior means that, while allocated buffers which are never freed may, - in fact, be garbage collected, they continue to count against the high water - mark limit. - - Accordingly, you should *always* free allocated buffers in order to prevent - the pool from believing that non-freed buffers are continually in use. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.nbytes - - -{{alias}}.factory( [options] ) - Creates a typed array pool. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.highWaterMark: integer (optional) - Maximum total memory (in bytes) which can be allocated. - - Returns - ------- - fcn: Function - Function for creating typed arrays from a typed array memory pool. - - Examples - -------- - > var pool = {{alias}}.factory(); - > var arr1 = pool( 3, 'float64' ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1014bba..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,193 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-empty */ -/* tslint:disable:no-unused-expression */ - -import typedarraypool = require( './index' ); - - -// TESTS // - -// The function returns a typed array or null... -{ - typedarraypool(); // $ExpectType TypedArrayOrNull - typedarraypool( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the function is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool( true ); // $ExpectError - typedarraypool( false ); // $ExpectError - typedarraypool( null ); // $ExpectError - typedarraypool( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized data type... -{ - typedarraypool( 4, true ); // $ExpectError - typedarraypool( 4, false ); // $ExpectError - typedarraypool( 4, null ); // $ExpectError - typedarraypool( 4, 'abc' ); // $ExpectError - typedarraypool( 4, 123 ); // $ExpectError - typedarraypool( 4, [] ); // $ExpectError - typedarraypool( 4, {} ); // $ExpectError - typedarraypool( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an incorrect number of arguments... -{ - typedarraypool( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `malloc` method which returns a typed array or null... -{ - typedarraypool.malloc(); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.malloc( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `malloc` method is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool.malloc( true ); // $ExpectError - typedarraypool.malloc( false ); // $ExpectError - typedarraypool.malloc( null ); // $ExpectError - typedarraypool.malloc( {} ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.malloc( 4, true ); // $ExpectError - typedarraypool.malloc( 4, false ); // $ExpectError - typedarraypool.malloc( 4, null ); // $ExpectError - typedarraypool.malloc( 4, 'abc' ); // $ExpectError - typedarraypool.malloc( 4, 123 ); // $ExpectError - typedarraypool.malloc( 4, [] ); // $ExpectError - typedarraypool.malloc( 4, {} ); // $ExpectError - typedarraypool.malloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided an incorrect number of arguments... -{ - typedarraypool.malloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `calloc` method which returns a typed array or null... -{ - typedarraypool.calloc(); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `calloc` method is provided a first argument which is not a number... -{ - typedarraypool.calloc( 'abc' ); // $ExpectError - typedarraypool.calloc( true ); // $ExpectError - typedarraypool.calloc( false ); // $ExpectError - typedarraypool.calloc( null ); // $ExpectError - typedarraypool.calloc( {} ); // $ExpectError - typedarraypool.calloc( [] ); // $ExpectError - typedarraypool.calloc( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.calloc( 4, true ); // $ExpectError - typedarraypool.calloc( 4, false ); // $ExpectError - typedarraypool.calloc( 4, null ); // $ExpectError - typedarraypool.calloc( 4, 'abc' ); // $ExpectError - typedarraypool.calloc( 4, 123 ); // $ExpectError - typedarraypool.calloc( 4, [] ); // $ExpectError - typedarraypool.calloc( 4, {} ); // $ExpectError - typedarraypool.calloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided an incorrect number of arguments... -{ - typedarraypool.calloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `factory` method which returns a typed array pool.. -{ - typedarraypool.factory(); // $ExpectType Pool - typedarraypool.factory( { 'highWaterMark': 556 } ); // $ExpectType Pool -} - -// The compiler throws an error if the `factory` method is provided a `highWaterMark` option which is not a number... -{ - typedarraypool.factory( { 'highWaterMark': true } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': false } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': 'abc' } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': null } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': [] } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': {} } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an incorrect number of arguments... -{ - typedarraypool.factory( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` method which returns void... -{ - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.free( arr ); // $ExpectType void -} - -// The compiler throws an error if the `free` method is provided a first argument which is neither a typed array nor array buffer... -{ - typedarraypool.free( true ); // $ExpectError - typedarraypool.free( false ); // $ExpectError - typedarraypool.free( 123 ); // $ExpectError - typedarraypool.free( 'abc' ); // $ExpectError - typedarraypool.free( null ); // $ExpectError - typedarraypool.free( {} ); // $ExpectError - typedarraypool.free( ( x: number ): number => x ); // $ExpectError -} - -// Attached to the main export is a `clear` method which returns void... -{ - typedarraypool.clear(); // $ExpectType void -} - -// The compiler throws an error if the `clear` method is provided arguments... -{ - typedarraypool.clear( {} ); // $ExpectError - typedarraypool.clear( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `highWaterMark` property... -{ - typedarraypool.highWaterMark; // $ExpectType number -} - -// Attached to the main export is a `nbytes` property... -{ - typedarraypool.nbytes; // $ExpectType number -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 24a7846..0000000 --- a/examples/index.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 randu = require( '@stdlib/random-base-randu' ); -var typedarraypool = require( './../lib' ); - -// Create a typed array pool which can allocate at most 1GB: -var typedarray = typedarraypool.factory({ - 'highWaterMark': 1e9 -}); - -// Inspect the pool: -console.log( 'Max bytes: %d', typedarray.highWaterMark ); -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Allocate an array for storing double-precision floating-point numbers: -var arr1 = typedarray( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Fill the array... -var i; -for ( i = 0; i < arr1.length; i++ ) { - arr1[ i ] = randu(); -} - -// Inspect array contents: -console.log( arr1 ); - -// Free the array: -typedarray.free( arr1 ); - -// Allocate another array similar to the previous one: -var arr2 = typedarray( 5, 'float64' ); -// returns - -// Check that we have been returned a new typed array view: -console.log( arr2 === arr1 ); -// => false - -// Inspect array contents: -console.log( arr2 ); - -// Free the array: -typedarray.free( arr2 ); - -// Allocate an initialized array: -var arr3 = typedarray.calloc( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect array contents: -console.log( arr3 ); - -// Free the array: -typedarray.free( arr3 ); - -// Clear the pool: -typedarray.clear(); - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 239fcdc..4500b91 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; import ArrayBuffer = require( '@stdlib/array-buffer' ); diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..de19cff --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";var w={highWaterMark:9007199254740992};function M(e,t){return y(t)?k(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(f("00d35","highWaterMark",e.highWaterMark)):null:new TypeError(f("00d2h",t))}function W(e){var t,r;for(t=[],r=0;rL.highWaterMark?null:(t=new c(e),k+=e,t)}function z(e,t,r){var s;return 0===t?new e(0):null===(s=q(b(t)*E[r]))?s:new e(s,0,t)}function C(){var e,i,n,l,j,c,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(n=d(i)))throw new TypeError(f("00d2k",i));if(e<=0)return new n(0);if(r(arguments[0]))return z(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,m(l)?l=h(l,0):o(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=z(n,u,i)))return j;if(B(j)||A(j))return j.set(l),j;for(g=p(l).getter,c=p(j).setter,b=0;b0){for(t=u(v(e.byteLength)),t=x(T.length-1,t),r=T[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = copy( defaults );\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '00d2k', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring user's don't do ill-advised things...\n\t\t\tget = arraylike2object( arr ).getter;\n\t\t\tset = arraylike2object( out ).setter;\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '00d33', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool' ;\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","copy","defaults","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","arraylike2object","getter","setter","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;qpEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,QAAS,gBAAiBP,EAAKI,gBAGxD,KARC,IAAIE,UAAWC,EAAQ,QAASN,ICtBzC,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,kHCcJG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,EAUzB,SAASK,EAAiBD,GACzB,OAASA,aAAeF,EA8BzB,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EAAOsB,EAAMC,GACRC,UAAUC,SACdJ,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOkB,EAAYC,EAAMC,EAAM5B,EAAKI,iBACpCgB,EAAS,EAETS,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB9B,EAAKI,eAC3C8B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOf,EAUR,SAASgB,EAAa3B,GACrB,IAAI4B,EACA1B,EAMJ,OAHAA,EAAIiB,EAAMnB,IAGDD,EAAKiB,QAAUjB,EAAMG,GAAIc,OAC1BjB,EAAMG,GAAI2B,MAGblB,EAAOX,EAAIT,EAAKI,cACb,MAERiC,EAAM,IAAIE,EAAa9B,GAGvBW,GAAUX,EAEH4B,GAYR,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,GAmB1B,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAxB,EACAP,EACAqC,EACAC,EACAN,EACA/B,EAUJ,GALCgC,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAO3B,EAAO6B,IAEb,MAAM,IAAIrC,UAAWC,EAAQ,QAASoC,IAEvC,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKpC,EAAsBmB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAzB,EAAMO,UAAW,IACPC,OACL0B,EAAmBlC,GACvBA,EAAMmC,EAAgBnC,EAAK,GAChBoC,EAAkBpC,GAC7BA,EAAMqC,EAAerC,EAAK,GACf,WAAWsC,KAAMZ,KAE5BD,GAAO,GAGK,QADbhC,EAAM8B,EAAYC,EAAMC,EAAKC,IAE5B,OAAOjC,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAIqC,IAAK9B,GACFP,EAKR,IAFAsC,EAAMQ,EAAkBvC,GAAMwC,OAC9BV,EAAMS,EAAkB9C,GAAMgD,OACxB/C,EAAI,EAAGA,EAAI+B,EAAK/B,IACrBoC,EAAKrC,EAAKC,EAAGqC,EAAK/B,EAAKN,IAExB,OAAOD,EAER,MAAM,IAAIJ,UAAWC,EAAQ,QAASiB,UAAW,KAiBlD,SAASO,IACR,IAAIe,EACApC,EACAiD,EACAhD,EAUJ,GAAa,QANZD,EADc,KADfoC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCmC,EADIzC,EAAiBR,GACf0C,EAAgB1C,EAAK,GAChBM,EAAgBN,GACrB4C,EAAe5C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAIgD,EAAIlC,OAAQd,IAC5BgD,EAAKhD,GAAM,EAGb,OAAOD,EAeR,SAASsB,EAAMK,GACd,IAAI5B,EACAmD,EACAjD,EACJ,GAAKkD,EAAkBxB,IAASA,EAAIyB,OACnCzB,EAAMA,EAAIyB,YACJ,IAAMC,EAAe1B,GAC3B,MAAM,IAAI/B,UAAWC,EAAQ,4EAA6E8B,IAE3G,GAAKA,EAAI2B,WAAa,EAAI,CAQzB,IAPAvD,EAAIwD,EAAOrC,EAAMS,EAAI2B,aAGrBvD,EAAIyD,EAAK1D,EAAKiB,OAAO,EAAGhB,GAGxBmD,EAAIpD,EAAMC,GACJE,EAAI,EAAGA,EAAIiD,EAAEnC,OAAQd,IAC1B,GAAKiD,EAAGjD,KAAQ0B,EACf,OAAO,EAITuB,EAAEhD,KAAMyB,GAET,OAAO,EAQR,SAASJ,IACR,IAAItB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKiB,OAAQd,IAC7BH,EAAMG,GAAIc,OAAS,EAEpBL,EAAS,GCjTR,IAAC+C,EAAiBhD,ICPrBU,EAAAuC,EAAA,UAAAjD"} \ No newline at end of file diff --git a/lib/bytes_per_element.json b/lib/bytes_per_element.json deleted file mode 100644 index f97fe70..0000000 --- a/lib/bytes_per_element.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "float64": 8, - "float32": 4, - "int16": 2, - "int32": 4, - "int8": 1, - "uint16": 2, - "uint32": 4, - "uint8": 1, - "uint8c": 1, - "complex64": 8, - "complex128": 16 -} diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index c71c8f2..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "highWaterMark": 9007199254740992 -} diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index b75e403..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,370 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var isComplex64Array = require( '@stdlib/assert-is-complex64array' ); -var isComplex128Array = require( '@stdlib/assert-is-complex128array' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var ctors = require( '@stdlib/array-typed-ctors' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( '@stdlib/utils-copy' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil = require( '@stdlib/math-base-special-ceil' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); -var log2 = require( '@stdlib/math-base-special-log2' ); -var min = require( '@stdlib/math-base-special-min' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); -var createPool = require( './pool.js' ); -var BYTES_PER_ELEMENT = require( './bytes_per_element.json' ); - - -// VARIABLES // - -var Complex64Array = ctors( 'complex64' ); -var Complex128Array = ctors( 'complex128' ); - - -// FUNCTIONS // - -/** -* Tests whether an array is a single-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a single-precision complex floating-point number array -*/ -function isCmplx64Array( arr ) { - return ( arr instanceof Complex64Array ); -} - -/** -* Tests whether an array is a double-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a double-precision complex floating-point number array -*/ -function isCmplx128Array( arr ) { - return ( arr instanceof Complex128Array ); -} - - -// MAIN // - -/** -* Creates a typed array pool. -* -* @param {Options} [options] - pool options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} allocator -* -* @example -* var typedarraypool = factory(); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -function factory( options ) { - var nbytes; - var pool; - var opts; - var err; - - opts = copy( defaults ); - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - pool = createPool( ceil( log2( opts.highWaterMark ) ) ); - nbytes = 0; - - setReadOnly( malloc, 'malloc', malloc ); // circular reference - setReadOnly( malloc, 'calloc', calloc ); - setReadOnly( malloc, 'free', free ); - setReadOnly( malloc, 'clear', clear ); - setReadOnly( malloc, 'highWaterMark', opts.highWaterMark ); - setReadOnlyAccessor( malloc, 'nbytes', getBytes ); - - return malloc; - - /** - * Returns the number of allocated bytes. - * - * @private - * @returns {NonNegativeInteger} number of allocated bytes - */ - function getBytes() { - return nbytes; - } - - /** - * Returns an array buffer. - * - * @private - * @param {NonNegativeInteger} n - number of bytes - * @returns {(ArrayBuffer|null)} array buffer or null - */ - function arraybuffer( n ) { - var buf; - var i; - - // Convert the number of bytes to an index in our pool table: - i = log2( n ); - - // If we already have an available array buffer, use it... - if ( i < pool.length && pool[ i ].length ) { - return pool[ i ].pop(); - } - // Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate... - if ( nbytes+n > opts.highWaterMark ) { - return null; - } - buf = new ArrayBuffer( n ); - - // Update the running counter of allocated bytes: - nbytes += n; - - return buf; - } - - /** - * Returns a typed array. - * - * @private - * @param {Function} ctor - typed array constructor - * @param {NonNegativeInteger} len - view length - * @param {string} dtype - data type - * @returns {(TypedArray|null)} typed array or null - */ - function typedarray( ctor, len, dtype ) { - var buf; - if ( len === 0 ) { - return new ctor( 0 ); - } - buf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] ); - if ( buf === null ) { - return buf; - } - return new ctor( buf, 0, len ); - } - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length or an array-like object - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function malloc() { - var nargs; - var dtype; - var ctor; - var arr; - var out; - var set; - var get; - var len; - var i; - - nargs = arguments.length; - if ( nargs && isString( arguments[ nargs-1 ] ) ) { - nargs -= 1; - dtype = arguments[ nargs ]; - } else { - dtype = 'float64'; - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( '00d2k', dtype ) ); - } - if ( nargs <= 0 ) { - return new ctor( 0 ); - } - // Check if provided a typed array length... - if ( isNonNegativeInteger( arguments[ 0 ] ) ) { - return typedarray( ctor, arguments[ 0 ], dtype ); - } - // Check if provided an array-like object containing data elements... - if ( isCollection( arguments[ 0 ] ) ) { - arr = arguments[ 0 ]; - len = arr.length; - if ( isComplex128Array( arr ) ) { - arr = reinterpret128( arr, 0 ); - } else if ( isComplex64Array( arr ) ) { - arr = reinterpret64( arr, 0 ); - } else if ( /^complex/.test( dtype ) ) { - // Assume we've been provided an array of interleaved real and imaginary components... - len /= 2; - } - out = typedarray( ctor, len, dtype ); - if ( out === null ) { - return out; - } - if ( isCmplx128Array( out ) || isCmplx64Array( out ) ) { - out.set( arr ); - return out; - } - // Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other "unsafe" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring user's don't do ill-advised things... - get = arraylike2object( arr ).getter; - set = arraylike2object( out ).setter; - for ( i = 0; i < len; i++ ) { - set( out, i, get( arr, i ) ); - } - return out; - } - throw new TypeError( format( '00d33', arguments[ 0 ] ) ); - } - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {NonNegativeInteger} [len=0] - array length - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function calloc() { - var nargs; - var out; - var tmp; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - out = malloc(); - } else if ( nargs === 1 ) { - out = malloc( arguments[ 0 ] ); - } else { - out = malloc( arguments[ 0 ], arguments[ 1 ] ); - } - if ( out !== null ) { - // Initialize the memory... - if ( isCmplx128Array( out ) ) { - tmp = reinterpret128( out, 0 ); - } else if ( isCmplx64Array( out ) ) { - tmp = reinterpret64( out, 0 ); - } else { - tmp = out; - } - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = 0.0; - } - } - return out; - } - - /** - * Frees a typed array or typed array buffer. - * - * ## Notes - * - * - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., "freeing" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool. - * - * @private - * @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free - * @throws {TypeError} must provide a typed array or typed array buffer - * @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed - */ - function free( buf ) { - var n; - var p; - var i; - if ( isTypedArrayLike( buf ) && buf.buffer ) { - buf = buf.buffer; - } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) ); - } - if ( buf.byteLength > 0 ) { - n = floor( log2( buf.byteLength ) ); - - // Prohibit "freeing" array buffers which would potentially allow users to circumvent high water mark limits: - n = min( pool.length-1, n ); - - // Ensure that we do not attempt to free the same buffer more than once... - p = pool[ n ]; - for ( i = 0; i < p.length; i++ ) { - if ( p[ i ] === buf ) { - return false; - } - } - // Add the buffer to our pool of free buffers: - p.push( buf ); - } - return true; - } - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @private - */ - function clear() { - var i; - for ( i = 0; i < pool.length; i++ ) { - pool[ i ].length = 0; - } - nbytes = 0; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6c12a4e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Typed array pool. -* -* @module @stdlib/array-pool -* -* @example -* var typedarraypool = require( '@stdlib/array-pool' ); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8f69ee3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,63 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @name typedarraypool -* @type {Function} -* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a valid array length or an array-like object -* @throws {TypeError} must provide a recognized data type -* @returns {(TypedArray|null)} typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -var typedarraypool = factory(); - - -// EXPORTS // - -module.exports = typedarraypool; diff --git a/lib/pool.js b/lib/pool.js deleted file mode 100644 index 5abd287..0000000 --- a/lib/pool.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Initializes a cache for pooled typed array buffers. -* -* @private -* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size -* @returns {ArrayArray} initialized cache -*/ -function pool( n ) { - var out; - var i; - - out = []; - for ( i = 0; i < n+1; i++ ) { - out.push( [] ); - } - return out; -} - - -// EXPORTS // - -module.exports = pool; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 4135ec9..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'highWaterMark': 1024 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '00d2h', options ) ); - } - if ( hasOwnProp( options, 'highWaterMark' ) ) { - opts.highWaterMark = options.highWaterMark; - if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( '00d35', 'highWaterMark', opts.highWaterMark ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 558fca7..42614cf 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Typed array pool.", "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,76 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.0.x", - "@stdlib/array-buffer": "^0.0.x", - "@stdlib/array-typed-ctors": "^0.0.x", - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-arraybuffer": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-complex128array": "^0.0.x", - "@stdlib/assert-is-complex64array": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/assert-is-typed-array-like": "^0.0.x", - "@stdlib/math-base-special-ceil": "^0.0.x", - "@stdlib/math-base-special-ceil2": "^0.0.x", - "@stdlib/math-base-special-floor": "^0.0.x", - "@stdlib/math-base-special-log2": "^0.0.x", - "@stdlib/math-base-special-min": "^0.0.x", - "@stdlib/strided-base-reinterpret-complex128": "^0.0.x", - "@stdlib/strided-base-reinterpret-complex64": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-copy": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.0.x", - "@stdlib/array-complex64": "^0.0.x", - "@stdlib/array-float32": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/array-int16": "^0.0.x", - "@stdlib/array-int32": "^0.0.x", - "@stdlib/array-int8": "^0.0.x", - "@stdlib/array-uint16": "^0.0.x", - "@stdlib/array-uint32": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/array-uint8c": "^0.0.x", - "@stdlib/assert-instance-of": "^0.0.x", - "@stdlib/assert-is-complex-typed-array": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-typed-array": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/complex-float32": "^0.0.x", - "@stdlib/complex-float64": "^0.0.x", - "@stdlib/complex-imag": "^0.0.x", - "@stdlib/complex-imagf": "^0.0.x", - "@stdlib/complex-real": "^0.0.x", - "@stdlib/complex-realf": "^0.0.x", - "@stdlib/math-base-special-pow": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d747953 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 396aee2..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,2240 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function (no options)', function test( t ) { - t.strictEqual( typeof factory(), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - t.strictEqual( typeof factory( {} ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided a `highWaterMark` option which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (length)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a function which returns a typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, length)', function test( t ) { - var typedarraypool = factory(); - var arr; - - arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a `malloc` method which is a circular reference', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - var buf; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the returned function is a property which returns the pool\'s high water mark', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function supports specifying a high water mark which limits the total amount of memory a pool can allocate', function test( t ) { - var typedarraypool; - var arr1; - var arr2; - - typedarraypool = factory({ - 'highWaterMark': 64 // bytes - }); - - typedarraypool.clear(); - - arr1 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr1.length, 8, 'returns expected value' ); - t.strictEqual( arr1.byteLength, 64, 'returns expected value' ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - typedarraypool.free( arr1 ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Create an array which is less than or equal to the high water mark: - arr2 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr2.length, 8, 'returns expected value' ); - t.strictEqual( arr2.byteLength, 64, 'returns expected value' ); - - typedarraypool.free( arr2 ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a property which returns the total number of accumulated bytes', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var typedarraypool; - var arrs; - var i; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 54aa5ee..0000000 --- a/test/test.js +++ /dev/null @@ -1,1797 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var typedarraypool = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -}); From 77b73aa2478780161c61f423dbd32f4eb4096583 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 20:51:13 +0000 Subject: [PATCH 005/103] Transform error messages --- lib/factory.js | 6 +++--- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 2401100..b75e403 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -33,7 +33,7 @@ var ctors = require( '@stdlib/array-typed-ctors' ); var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( '@stdlib/utils-copy' ); var ArrayBuffer = require( '@stdlib/array-buffer' ); var ceil = require( '@stdlib/math-base-special-ceil' ); @@ -226,7 +226,7 @@ function factory( options ) { } ctor = ctors( dtype ); if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '00d2k', dtype ) ); } if ( nargs <= 0 ) { return new ctor( 0 ); @@ -263,7 +263,7 @@ function factory( options ) { } return out; } - throw new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) ); + throw new TypeError( format( '00d33', arguments[ 0 ] ) ); } /** diff --git a/lib/validate.js b/lib/validate.js index ce54890..4135ec9 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '00d2h', options ) ); } if ( hasOwnProp( options, 'highWaterMark' ) ) { opts.highWaterMark = options.highWaterMark; if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) ); + return new TypeError( format( '00d35', 'highWaterMark', opts.highWaterMark ) ); } } return null; diff --git a/package.json b/package.json index 50986ed..558fca7 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "@stdlib/math-base-special-min": "^0.0.x", "@stdlib/strided-base-reinterpret-complex128": "^0.0.x", "@stdlib/strided-base-reinterpret-complex64": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-copy": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", From a7643db2560063a318d97460d01e72353b1c63dd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 08:59:21 +0000 Subject: [PATCH 006/103] Remove files --- index.d.ts | 359 ------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 3053 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 4500b91..0000000 --- a/index.d.ts +++ /dev/null @@ -1,359 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; -import ArrayBuffer = require( '@stdlib/array-buffer' ); - -/** -* Typed array or null. -*/ -type TypedArrayOrNull = RealOrComplexTypedArray | null; - -/** -* Interface defining pool options. -*/ -interface Options { - /** - * Maximum total memory which can be allocated. - */ - highWaterMark?: number; -} - -/** -* Pool interface. -*/ -interface Pool { - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr = typedarraypool(); - * // returns [] - * - * @example - * var arr = typedarraypool( 'float32' ); - * // returns [] - */ - ( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * // Allocate an array of doubles: - * var arr = typedarraypool( 5, 'float64' ); - * // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * typedarraypool.free( arr ); - * - * @example - * var arr1 = typedarraypool( [ 0.5, 0.5, 0.5 ] ); - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * @example - * var arr1 = [ 0.5, 0.5, 0.5 ]; - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - */ - ( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc(); - * // returns [] - * - * var arr2 = typedarraypool.calloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param length - typed array length - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc( 5 ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * var arr2 = typedarraypool.calloc( 5, 'uint8' ); - * // returns [ 0, 0, 0, 0, 0 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( length: number, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc(); - * // returns [] - * - * var arr2 = typedarraypool.malloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc( 5 ); - * // returns - * - * var arr2 = typedarraypool.malloc( 5, 'uint8' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 5.0, -3.0, 2.0 ] ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr2 = typedarraypool.malloc( arr1 ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr3 = typedarraypool.malloc( arr1, 'int32' ); - * // returns [ 5, -3, 2 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * typedarraypool.free( arr3 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ] ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * var arr2 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ], 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Frees a typed array or typed array buffer for use in a future allocation. - * - * @param buf - typed array or typed array buffer to free - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array for use in a future allocation: - * typedarraypool.free( arr ); - * - * // Create another typed array: - * arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array buffer for use in a future allocation: - * typedarraypool.free( arr.buffer ); - */ - free( buf: RealOrComplexTypedArray | ArrayBuffer ): void; - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr ); - * - * // ... - * - * // Clear all freed buffers: - * typedarraypool.clear(); - */ - clear(): void; - - /** - * Read-only property returning the pool's high water mark. - * - * ## Notes - * - * - Once a high water mark is reached, typed array allocation fails. - * - * @example - * var limit = typedarraypool.highWaterMark; - * // returns - */ - readonly highWaterMark: number; - - /** - * Read-only property returning the total number of allocated bytes. - * - * @example - * var arr = typedarraypool( 5, 'float64' ); - * - * var nbytes = typedarraypool.nbytes; - * // returns - */ - readonly nbytes: number; - - /** - * Creates a typed array pool. - * - * @param options - pool options - * @param options.highWaterMark - maximum total memory which can be allocated - * @throws must provide valid options - * @returns allocator - * - * @example - * var allocator = typedarraypool.factory(); - * - * // Allocate an array of doubles: - * var arr = allocator( 5, 'float64' ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * allocator.free( arr ); - */ - factory( options?: Options ): Pool; -} - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @param arg - an array length or an array-like object -* @param dtype - data type (default: 'float64') -* @returns typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -declare var typedarraypool: Pool; - - -// EXPORTS // - -export = typedarraypool; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index de19cff..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";var w={highWaterMark:9007199254740992};function M(e,t){return y(t)?k(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(f("00d35","highWaterMark",e.highWaterMark)):null:new TypeError(f("00d2h",t))}function W(e){var t,r;for(t=[],r=0;rL.highWaterMark?null:(t=new c(e),k+=e,t)}function z(e,t,r){var s;return 0===t?new e(0):null===(s=q(b(t)*E[r]))?s:new e(s,0,t)}function C(){var e,i,n,l,j,c,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(n=d(i)))throw new TypeError(f("00d2k",i));if(e<=0)return new n(0);if(r(arguments[0]))return z(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,m(l)?l=h(l,0):o(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=z(n,u,i)))return j;if(B(j)||A(j))return j.set(l),j;for(g=p(l).getter,c=p(j).setter,b=0;b0){for(t=u(v(e.byteLength)),t=x(T.length-1,t),r=T[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = copy( defaults );\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '00d2k', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring user's don't do ill-advised things...\n\t\t\tget = arraylike2object( arr ).getter;\n\t\t\tset = arraylike2object( out ).setter;\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '00d33', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool' ;\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","copy","defaults","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","arraylike2object","getter","setter","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;qpEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,QAAS,gBAAiBP,EAAKI,gBAGxD,KARC,IAAIE,UAAWC,EAAQ,QAASN,ICtBzC,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,kHCcJG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,EAUzB,SAASK,EAAiBD,GACzB,OAASA,aAAeF,EA8BzB,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EAAOsB,EAAMC,GACRC,UAAUC,SACdJ,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOkB,EAAYC,EAAMC,EAAM5B,EAAKI,iBACpCgB,EAAS,EAETS,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB9B,EAAKI,eAC3C8B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOf,EAUR,SAASgB,EAAa3B,GACrB,IAAI4B,EACA1B,EAMJ,OAHAA,EAAIiB,EAAMnB,IAGDD,EAAKiB,QAAUjB,EAAMG,GAAIc,OAC1BjB,EAAMG,GAAI2B,MAGblB,EAAOX,EAAIT,EAAKI,cACb,MAERiC,EAAM,IAAIE,EAAa9B,GAGvBW,GAAUX,EAEH4B,GAYR,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,GAmB1B,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAxB,EACAP,EACAqC,EACAC,EACAN,EACA/B,EAUJ,GALCgC,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAO3B,EAAO6B,IAEb,MAAM,IAAIrC,UAAWC,EAAQ,QAASoC,IAEvC,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKpC,EAAsBmB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAzB,EAAMO,UAAW,IACPC,OACL0B,EAAmBlC,GACvBA,EAAMmC,EAAgBnC,EAAK,GAChBoC,EAAkBpC,GAC7BA,EAAMqC,EAAerC,EAAK,GACf,WAAWsC,KAAMZ,KAE5BD,GAAO,GAGK,QADbhC,EAAM8B,EAAYC,EAAMC,EAAKC,IAE5B,OAAOjC,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAIqC,IAAK9B,GACFP,EAKR,IAFAsC,EAAMQ,EAAkBvC,GAAMwC,OAC9BV,EAAMS,EAAkB9C,GAAMgD,OACxB/C,EAAI,EAAGA,EAAI+B,EAAK/B,IACrBoC,EAAKrC,EAAKC,EAAGqC,EAAK/B,EAAKN,IAExB,OAAOD,EAER,MAAM,IAAIJ,UAAWC,EAAQ,QAASiB,UAAW,KAiBlD,SAASO,IACR,IAAIe,EACApC,EACAiD,EACAhD,EAUJ,GAAa,QANZD,EADc,KADfoC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCmC,EADIzC,EAAiBR,GACf0C,EAAgB1C,EAAK,GAChBM,EAAgBN,GACrB4C,EAAe5C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAIgD,EAAIlC,OAAQd,IAC5BgD,EAAKhD,GAAM,EAGb,OAAOD,EAeR,SAASsB,EAAMK,GACd,IAAI5B,EACAmD,EACAjD,EACJ,GAAKkD,EAAkBxB,IAASA,EAAIyB,OACnCzB,EAAMA,EAAIyB,YACJ,IAAMC,EAAe1B,GAC3B,MAAM,IAAI/B,UAAWC,EAAQ,4EAA6E8B,IAE3G,GAAKA,EAAI2B,WAAa,EAAI,CAQzB,IAPAvD,EAAIwD,EAAOrC,EAAMS,EAAI2B,aAGrBvD,EAAIyD,EAAK1D,EAAKiB,OAAO,EAAGhB,GAGxBmD,EAAIpD,EAAMC,GACJE,EAAI,EAAGA,EAAIiD,EAAEnC,OAAQd,IAC1B,GAAKiD,EAAGjD,KAAQ0B,EACf,OAAO,EAITuB,EAAEhD,KAAMyB,GAET,OAAO,EAQR,SAASJ,IACR,IAAItB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKiB,OAAQd,IAC7BH,EAAMG,GAAIc,OAAS,EAEpBL,EAAS,GCjTR,IAAC+C,EAAiBhD,ICPrBU,EAAAuC,EAAA,UAAAjD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d747953..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From f6d033fe406186ac99b16471c66d432fd78a6db2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 09:00:14 +0000 Subject: [PATCH 007/103] 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 | 43 +- benchmark/benchmark.calloc.js | 246 -- benchmark/benchmark.factory.js | 71 - benchmark/benchmark.js | 246 -- benchmark/benchmark.length.complex128.js | 102 - benchmark/benchmark.length.complex64.js | 102 - benchmark/benchmark.length.float32.js | 102 - benchmark/benchmark.length.float64.js | 102 - benchmark/benchmark.length.int16.js | 102 - benchmark/benchmark.length.int32.js | 102 - benchmark/benchmark.length.int8.js | 102 - benchmark/benchmark.length.uint16.js | 102 - benchmark/benchmark.length.uint32.js | 102 - benchmark/benchmark.length.uint8.js | 102 - benchmark/benchmark.length.uint8c.js | 102 - benchmark/benchmark.malloc.js | 246 -- branches.md | 53 - docs/repl.txt | 347 --- docs/types/test.ts | 193 -- examples/index.js | 80 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/bytes_per_element.json | 13 - lib/defaults.json | 3 - lib/factory.js | 370 --- lib/index.js | 56 - lib/main.js | 63 - lib/pool.js | 44 - lib/validate.js | 66 - package.json | 97 +- stats.html | 2689 +++++++++++++++++++++ test/test.factory.js | 2240 ----------------- test/test.js | 1797 -------------- 57 files changed, 2718 insertions(+), 10223 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.calloc.js delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.complex128.js delete mode 100644 benchmark/benchmark.length.complex64.js delete mode 100644 benchmark/benchmark.length.float32.js delete mode 100644 benchmark/benchmark.length.float64.js delete mode 100644 benchmark/benchmark.length.int16.js delete mode 100644 benchmark/benchmark.length.int32.js delete mode 100644 benchmark/benchmark.length.int8.js delete mode 100644 benchmark/benchmark.length.uint16.js delete mode 100644 benchmark/benchmark.length.uint32.js delete mode 100644 benchmark/benchmark.length.uint8.js delete mode 100644 benchmark/benchmark.length.uint8c.js delete mode 100644 benchmark/benchmark.malloc.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/bytes_per_element.json delete mode 100644 lib/defaults.json delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/pool.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 1954da6..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-07-01T01:43:06.877Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ea35f20..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/array/pool) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 fc6d38a..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/array/pool) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -482,7 +481,7 @@ console.log( 'nbytes: %d', typedarray.nbytes ); ## 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]. @@ -548,7 +547,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm diff --git a/benchmark/benchmark.calloc.js b/benchmark/benchmark.calloc.js deleted file mode 100644 index e5a1c77..0000000 --- a/benchmark/benchmark.calloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':calloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index f7cd676..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = typedarray.factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:highWaterMark', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'highWaterMark': 0 - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.highWaterMark = i; - f = typedarray.factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a023d2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.complex128.js b/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 47b623b..0000000 --- a/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex64.js b/benchmark/benchmark.length.complex64.js deleted file mode 100644 index 40a412b..0000000 --- a/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float32.js b/benchmark/benchmark.length.float32.js deleted file mode 100644 index 0227ed7..0000000 --- a/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float64.js b/benchmark/benchmark.length.float64.js deleted file mode 100644 index 2dbac1c..0000000 --- a/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int16.js b/benchmark/benchmark.length.int16.js deleted file mode 100644 index e2a8adc..0000000 --- a/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int32.js b/benchmark/benchmark.length.int32.js deleted file mode 100644 index e4df0aa..0000000 --- a/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int8.js b/benchmark/benchmark.length.int8.js deleted file mode 100644 index 7ceac11..0000000 --- a/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint16.js b/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 9a532b6..0000000 --- a/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint32.js b/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 98f2d7f..0000000 --- a/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8.js b/benchmark/benchmark.length.uint8.js deleted file mode 100644 index 8359249..0000000 --- a/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8c.js b/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index d47d023..0000000 --- a/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.malloc.js b/benchmark/benchmark.malloc.js deleted file mode 100644 index d4eea72..0000000 --- a/benchmark/benchmark.malloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':malloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 8fce14f..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/array/pool" -click B href "https://github.com/stdlib-js/array-pool/tree/main" -click C href "https://github.com/stdlib-js/array-pool/tree/production" -click D href "https://github.com/stdlib-js/array-pool/tree/esm" -click E href "https://github.com/stdlib-js/array-pool/tree/deno" -click F href "https://github.com/stdlib-js/array-pool/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/pool -[production-url]: https://github.com/stdlib-js/array-pool/tree/production -[deno-url]: https://github.com/stdlib-js/array-pool/tree/deno -[umd-url]: https://github.com/stdlib-js/array-pool/tree/umd -[esm-url]: https://github.com/stdlib-js/array-pool/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5244595..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,347 +0,0 @@ - -{{alias}}( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - Memory is **uninitialized**, which means that the contents of a returned - typed array may contain sensitive contents. - - The function supports the following data types: - - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - The default typed array data type is `float64`. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}() - [] - > arr = {{alias}}( 'float32' ) - [] - - -{{alias}}( length[, dtype] ) - Returns an uninitialized typed array having a specified length from a typed - array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > arr = {{alias}}( 5, 'int32' ) - - - -{{alias}}( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - This method shares the same security vulnerabilities mentioned above. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc() - - > arr = {{alias}}.malloc( 'float32' ) - - - -{{alias}}.malloc( length[, dtype] ) - Returns a typed array having a specified length from a typed array memory - pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc( 5 ) - - > arr = {{alias}}.malloc( 5, 'int32' ) - - - -{{alias}}.malloc( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}.malloc( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.calloc( [dtype] ) - Returns a zero-initialized typed array from a typed array memory pool. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc() - [] - > arr = {{alias}}.calloc( 'float32' ) - [] - - -{{alias}}.calloc( length[, dtype] ) - Returns a zero-initialized typed array having a specified length from a - typed array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}.calloc( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}.free( buf ) - Frees a typed array or typed array buffer for use in a future allocation. - - Parameters - ---------- - buf: TypedArray|ArrayBuffer - Typed array or typed array buffer to free. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ) - - -{{alias}}.clear() - Clears the typed array pool allowing garbage collection of previously - allocated (and currently free) array buffers. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - > {{alias}}.clear() - - -{{alias}}.highWaterMark - Read-only property returning the pool's high water mark. - - Once a high water mark is reached, typed array allocation fails. - - Examples - -------- - > {{alias}}.highWaterMark - - -{{alias}}.nbytes - Read-only property returning the total number of allocated bytes. - - The returned value is the total accumulated value. Hence, anytime a pool - must allocate a new array buffer (i.e., more memory), the pool increments - this value. - - The only time this value is decremented is when a pool is cleared. - - This behavior means that, while allocated buffers which are never freed may, - in fact, be garbage collected, they continue to count against the high water - mark limit. - - Accordingly, you should *always* free allocated buffers in order to prevent - the pool from believing that non-freed buffers are continually in use. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.nbytes - - -{{alias}}.factory( [options] ) - Creates a typed array pool. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.highWaterMark: integer (optional) - Maximum total memory (in bytes) which can be allocated. - - Returns - ------- - fcn: Function - Function for creating typed arrays from a typed array memory pool. - - Examples - -------- - > var pool = {{alias}}.factory(); - > var arr1 = pool( 3, 'float64' ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1014bba..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,193 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-empty */ -/* tslint:disable:no-unused-expression */ - -import typedarraypool = require( './index' ); - - -// TESTS // - -// The function returns a typed array or null... -{ - typedarraypool(); // $ExpectType TypedArrayOrNull - typedarraypool( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the function is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool( true ); // $ExpectError - typedarraypool( false ); // $ExpectError - typedarraypool( null ); // $ExpectError - typedarraypool( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized data type... -{ - typedarraypool( 4, true ); // $ExpectError - typedarraypool( 4, false ); // $ExpectError - typedarraypool( 4, null ); // $ExpectError - typedarraypool( 4, 'abc' ); // $ExpectError - typedarraypool( 4, 123 ); // $ExpectError - typedarraypool( 4, [] ); // $ExpectError - typedarraypool( 4, {} ); // $ExpectError - typedarraypool( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an incorrect number of arguments... -{ - typedarraypool( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `malloc` method which returns a typed array or null... -{ - typedarraypool.malloc(); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.malloc( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `malloc` method is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool.malloc( true ); // $ExpectError - typedarraypool.malloc( false ); // $ExpectError - typedarraypool.malloc( null ); // $ExpectError - typedarraypool.malloc( {} ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.malloc( 4, true ); // $ExpectError - typedarraypool.malloc( 4, false ); // $ExpectError - typedarraypool.malloc( 4, null ); // $ExpectError - typedarraypool.malloc( 4, 'abc' ); // $ExpectError - typedarraypool.malloc( 4, 123 ); // $ExpectError - typedarraypool.malloc( 4, [] ); // $ExpectError - typedarraypool.malloc( 4, {} ); // $ExpectError - typedarraypool.malloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided an incorrect number of arguments... -{ - typedarraypool.malloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `calloc` method which returns a typed array or null... -{ - typedarraypool.calloc(); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `calloc` method is provided a first argument which is not a number... -{ - typedarraypool.calloc( 'abc' ); // $ExpectError - typedarraypool.calloc( true ); // $ExpectError - typedarraypool.calloc( false ); // $ExpectError - typedarraypool.calloc( null ); // $ExpectError - typedarraypool.calloc( {} ); // $ExpectError - typedarraypool.calloc( [] ); // $ExpectError - typedarraypool.calloc( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.calloc( 4, true ); // $ExpectError - typedarraypool.calloc( 4, false ); // $ExpectError - typedarraypool.calloc( 4, null ); // $ExpectError - typedarraypool.calloc( 4, 'abc' ); // $ExpectError - typedarraypool.calloc( 4, 123 ); // $ExpectError - typedarraypool.calloc( 4, [] ); // $ExpectError - typedarraypool.calloc( 4, {} ); // $ExpectError - typedarraypool.calloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided an incorrect number of arguments... -{ - typedarraypool.calloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `factory` method which returns a typed array pool.. -{ - typedarraypool.factory(); // $ExpectType Pool - typedarraypool.factory( { 'highWaterMark': 556 } ); // $ExpectType Pool -} - -// The compiler throws an error if the `factory` method is provided a `highWaterMark` option which is not a number... -{ - typedarraypool.factory( { 'highWaterMark': true } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': false } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': 'abc' } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': null } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': [] } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': {} } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an incorrect number of arguments... -{ - typedarraypool.factory( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` method which returns void... -{ - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.free( arr ); // $ExpectType void -} - -// The compiler throws an error if the `free` method is provided a first argument which is neither a typed array nor array buffer... -{ - typedarraypool.free( true ); // $ExpectError - typedarraypool.free( false ); // $ExpectError - typedarraypool.free( 123 ); // $ExpectError - typedarraypool.free( 'abc' ); // $ExpectError - typedarraypool.free( null ); // $ExpectError - typedarraypool.free( {} ); // $ExpectError - typedarraypool.free( ( x: number ): number => x ); // $ExpectError -} - -// Attached to the main export is a `clear` method which returns void... -{ - typedarraypool.clear(); // $ExpectType void -} - -// The compiler throws an error if the `clear` method is provided arguments... -{ - typedarraypool.clear( {} ); // $ExpectError - typedarraypool.clear( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `highWaterMark` property... -{ - typedarraypool.highWaterMark; // $ExpectType number -} - -// Attached to the main export is a `nbytes` property... -{ - typedarraypool.nbytes; // $ExpectType number -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 24a7846..0000000 --- a/examples/index.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 randu = require( '@stdlib/random-base-randu' ); -var typedarraypool = require( './../lib' ); - -// Create a typed array pool which can allocate at most 1GB: -var typedarray = typedarraypool.factory({ - 'highWaterMark': 1e9 -}); - -// Inspect the pool: -console.log( 'Max bytes: %d', typedarray.highWaterMark ); -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Allocate an array for storing double-precision floating-point numbers: -var arr1 = typedarray( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Fill the array... -var i; -for ( i = 0; i < arr1.length; i++ ) { - arr1[ i ] = randu(); -} - -// Inspect array contents: -console.log( arr1 ); - -// Free the array: -typedarray.free( arr1 ); - -// Allocate another array similar to the previous one: -var arr2 = typedarray( 5, 'float64' ); -// returns - -// Check that we have been returned a new typed array view: -console.log( arr2 === arr1 ); -// => false - -// Inspect array contents: -console.log( arr2 ); - -// Free the array: -typedarray.free( arr2 ); - -// Allocate an initialized array: -var arr3 = typedarray.calloc( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect array contents: -console.log( arr3 ); - -// Free the array: -typedarray.free( arr3 ); - -// Clear the pool: -typedarray.clear(); - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 239fcdc..4500b91 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; import ArrayBuffer = require( '@stdlib/array-buffer' ); diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..de19cff --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";var w={highWaterMark:9007199254740992};function M(e,t){return y(t)?k(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(f("00d35","highWaterMark",e.highWaterMark)):null:new TypeError(f("00d2h",t))}function W(e){var t,r;for(t=[],r=0;rL.highWaterMark?null:(t=new c(e),k+=e,t)}function z(e,t,r){var s;return 0===t?new e(0):null===(s=q(b(t)*E[r]))?s:new e(s,0,t)}function C(){var e,i,n,l,j,c,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(n=d(i)))throw new TypeError(f("00d2k",i));if(e<=0)return new n(0);if(r(arguments[0]))return z(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,m(l)?l=h(l,0):o(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=z(n,u,i)))return j;if(B(j)||A(j))return j.set(l),j;for(g=p(l).getter,c=p(j).setter,b=0;b0){for(t=u(v(e.byteLength)),t=x(T.length-1,t),r=T[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = copy( defaults );\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '00d2k', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring user's don't do ill-advised things...\n\t\t\tget = arraylike2object( arr ).getter;\n\t\t\tset = arraylike2object( out ).setter;\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '00d33', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool' ;\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","copy","defaults","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","arraylike2object","getter","setter","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;qpEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,QAAS,gBAAiBP,EAAKI,gBAGxD,KARC,IAAIE,UAAWC,EAAQ,QAASN,ICtBzC,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,kHCcJG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,EAUzB,SAASK,EAAiBD,GACzB,OAASA,aAAeF,EA8BzB,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EAAOsB,EAAMC,GACRC,UAAUC,SACdJ,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOkB,EAAYC,EAAMC,EAAM5B,EAAKI,iBACpCgB,EAAS,EAETS,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB9B,EAAKI,eAC3C8B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOf,EAUR,SAASgB,EAAa3B,GACrB,IAAI4B,EACA1B,EAMJ,OAHAA,EAAIiB,EAAMnB,IAGDD,EAAKiB,QAAUjB,EAAMG,GAAIc,OAC1BjB,EAAMG,GAAI2B,MAGblB,EAAOX,EAAIT,EAAKI,cACb,MAERiC,EAAM,IAAIE,EAAa9B,GAGvBW,GAAUX,EAEH4B,GAYR,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,GAmB1B,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAxB,EACAP,EACAqC,EACAC,EACAN,EACA/B,EAUJ,GALCgC,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAO3B,EAAO6B,IAEb,MAAM,IAAIrC,UAAWC,EAAQ,QAASoC,IAEvC,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKpC,EAAsBmB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAzB,EAAMO,UAAW,IACPC,OACL0B,EAAmBlC,GACvBA,EAAMmC,EAAgBnC,EAAK,GAChBoC,EAAkBpC,GAC7BA,EAAMqC,EAAerC,EAAK,GACf,WAAWsC,KAAMZ,KAE5BD,GAAO,GAGK,QADbhC,EAAM8B,EAAYC,EAAMC,EAAKC,IAE5B,OAAOjC,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAIqC,IAAK9B,GACFP,EAKR,IAFAsC,EAAMQ,EAAkBvC,GAAMwC,OAC9BV,EAAMS,EAAkB9C,GAAMgD,OACxB/C,EAAI,EAAGA,EAAI+B,EAAK/B,IACrBoC,EAAKrC,EAAKC,EAAGqC,EAAK/B,EAAKN,IAExB,OAAOD,EAER,MAAM,IAAIJ,UAAWC,EAAQ,QAASiB,UAAW,KAiBlD,SAASO,IACR,IAAIe,EACApC,EACAiD,EACAhD,EAUJ,GAAa,QANZD,EADc,KADfoC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCmC,EADIzC,EAAiBR,GACf0C,EAAgB1C,EAAK,GAChBM,EAAgBN,GACrB4C,EAAe5C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAIgD,EAAIlC,OAAQd,IAC5BgD,EAAKhD,GAAM,EAGb,OAAOD,EAeR,SAASsB,EAAMK,GACd,IAAI5B,EACAmD,EACAjD,EACJ,GAAKkD,EAAkBxB,IAASA,EAAIyB,OACnCzB,EAAMA,EAAIyB,YACJ,IAAMC,EAAe1B,GAC3B,MAAM,IAAI/B,UAAWC,EAAQ,4EAA6E8B,IAE3G,GAAKA,EAAI2B,WAAa,EAAI,CAQzB,IAPAvD,EAAIwD,EAAOrC,EAAMS,EAAI2B,aAGrBvD,EAAIyD,EAAK1D,EAAKiB,OAAO,EAAGhB,GAGxBmD,EAAIpD,EAAMC,GACJE,EAAI,EAAGA,EAAIiD,EAAEnC,OAAQd,IAC1B,GAAKiD,EAAGjD,KAAQ0B,EACf,OAAO,EAITuB,EAAEhD,KAAMyB,GAET,OAAO,EAQR,SAASJ,IACR,IAAItB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKiB,OAAQd,IAC7BH,EAAMG,GAAIc,OAAS,EAEpBL,EAAS,GCjTR,IAAC+C,EAAiBhD,ICPrBU,EAAAuC,EAAA,UAAAjD"} \ No newline at end of file diff --git a/lib/bytes_per_element.json b/lib/bytes_per_element.json deleted file mode 100644 index f97fe70..0000000 --- a/lib/bytes_per_element.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "float64": 8, - "float32": 4, - "int16": 2, - "int32": 4, - "int8": 1, - "uint16": 2, - "uint32": 4, - "uint8": 1, - "uint8c": 1, - "complex64": 8, - "complex128": 16 -} diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index c71c8f2..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "highWaterMark": 9007199254740992 -} diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index b75e403..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,370 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var isComplex64Array = require( '@stdlib/assert-is-complex64array' ); -var isComplex128Array = require( '@stdlib/assert-is-complex128array' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var ctors = require( '@stdlib/array-typed-ctors' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( '@stdlib/utils-copy' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil = require( '@stdlib/math-base-special-ceil' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); -var log2 = require( '@stdlib/math-base-special-log2' ); -var min = require( '@stdlib/math-base-special-min' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); -var createPool = require( './pool.js' ); -var BYTES_PER_ELEMENT = require( './bytes_per_element.json' ); - - -// VARIABLES // - -var Complex64Array = ctors( 'complex64' ); -var Complex128Array = ctors( 'complex128' ); - - -// FUNCTIONS // - -/** -* Tests whether an array is a single-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a single-precision complex floating-point number array -*/ -function isCmplx64Array( arr ) { - return ( arr instanceof Complex64Array ); -} - -/** -* Tests whether an array is a double-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a double-precision complex floating-point number array -*/ -function isCmplx128Array( arr ) { - return ( arr instanceof Complex128Array ); -} - - -// MAIN // - -/** -* Creates a typed array pool. -* -* @param {Options} [options] - pool options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} allocator -* -* @example -* var typedarraypool = factory(); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -function factory( options ) { - var nbytes; - var pool; - var opts; - var err; - - opts = copy( defaults ); - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - pool = createPool( ceil( log2( opts.highWaterMark ) ) ); - nbytes = 0; - - setReadOnly( malloc, 'malloc', malloc ); // circular reference - setReadOnly( malloc, 'calloc', calloc ); - setReadOnly( malloc, 'free', free ); - setReadOnly( malloc, 'clear', clear ); - setReadOnly( malloc, 'highWaterMark', opts.highWaterMark ); - setReadOnlyAccessor( malloc, 'nbytes', getBytes ); - - return malloc; - - /** - * Returns the number of allocated bytes. - * - * @private - * @returns {NonNegativeInteger} number of allocated bytes - */ - function getBytes() { - return nbytes; - } - - /** - * Returns an array buffer. - * - * @private - * @param {NonNegativeInteger} n - number of bytes - * @returns {(ArrayBuffer|null)} array buffer or null - */ - function arraybuffer( n ) { - var buf; - var i; - - // Convert the number of bytes to an index in our pool table: - i = log2( n ); - - // If we already have an available array buffer, use it... - if ( i < pool.length && pool[ i ].length ) { - return pool[ i ].pop(); - } - // Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate... - if ( nbytes+n > opts.highWaterMark ) { - return null; - } - buf = new ArrayBuffer( n ); - - // Update the running counter of allocated bytes: - nbytes += n; - - return buf; - } - - /** - * Returns a typed array. - * - * @private - * @param {Function} ctor - typed array constructor - * @param {NonNegativeInteger} len - view length - * @param {string} dtype - data type - * @returns {(TypedArray|null)} typed array or null - */ - function typedarray( ctor, len, dtype ) { - var buf; - if ( len === 0 ) { - return new ctor( 0 ); - } - buf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] ); - if ( buf === null ) { - return buf; - } - return new ctor( buf, 0, len ); - } - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length or an array-like object - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function malloc() { - var nargs; - var dtype; - var ctor; - var arr; - var out; - var set; - var get; - var len; - var i; - - nargs = arguments.length; - if ( nargs && isString( arguments[ nargs-1 ] ) ) { - nargs -= 1; - dtype = arguments[ nargs ]; - } else { - dtype = 'float64'; - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( '00d2k', dtype ) ); - } - if ( nargs <= 0 ) { - return new ctor( 0 ); - } - // Check if provided a typed array length... - if ( isNonNegativeInteger( arguments[ 0 ] ) ) { - return typedarray( ctor, arguments[ 0 ], dtype ); - } - // Check if provided an array-like object containing data elements... - if ( isCollection( arguments[ 0 ] ) ) { - arr = arguments[ 0 ]; - len = arr.length; - if ( isComplex128Array( arr ) ) { - arr = reinterpret128( arr, 0 ); - } else if ( isComplex64Array( arr ) ) { - arr = reinterpret64( arr, 0 ); - } else if ( /^complex/.test( dtype ) ) { - // Assume we've been provided an array of interleaved real and imaginary components... - len /= 2; - } - out = typedarray( ctor, len, dtype ); - if ( out === null ) { - return out; - } - if ( isCmplx128Array( out ) || isCmplx64Array( out ) ) { - out.set( arr ); - return out; - } - // Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other "unsafe" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring user's don't do ill-advised things... - get = arraylike2object( arr ).getter; - set = arraylike2object( out ).setter; - for ( i = 0; i < len; i++ ) { - set( out, i, get( arr, i ) ); - } - return out; - } - throw new TypeError( format( '00d33', arguments[ 0 ] ) ); - } - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {NonNegativeInteger} [len=0] - array length - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function calloc() { - var nargs; - var out; - var tmp; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - out = malloc(); - } else if ( nargs === 1 ) { - out = malloc( arguments[ 0 ] ); - } else { - out = malloc( arguments[ 0 ], arguments[ 1 ] ); - } - if ( out !== null ) { - // Initialize the memory... - if ( isCmplx128Array( out ) ) { - tmp = reinterpret128( out, 0 ); - } else if ( isCmplx64Array( out ) ) { - tmp = reinterpret64( out, 0 ); - } else { - tmp = out; - } - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = 0.0; - } - } - return out; - } - - /** - * Frees a typed array or typed array buffer. - * - * ## Notes - * - * - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., "freeing" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool. - * - * @private - * @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free - * @throws {TypeError} must provide a typed array or typed array buffer - * @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed - */ - function free( buf ) { - var n; - var p; - var i; - if ( isTypedArrayLike( buf ) && buf.buffer ) { - buf = buf.buffer; - } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) ); - } - if ( buf.byteLength > 0 ) { - n = floor( log2( buf.byteLength ) ); - - // Prohibit "freeing" array buffers which would potentially allow users to circumvent high water mark limits: - n = min( pool.length-1, n ); - - // Ensure that we do not attempt to free the same buffer more than once... - p = pool[ n ]; - for ( i = 0; i < p.length; i++ ) { - if ( p[ i ] === buf ) { - return false; - } - } - // Add the buffer to our pool of free buffers: - p.push( buf ); - } - return true; - } - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @private - */ - function clear() { - var i; - for ( i = 0; i < pool.length; i++ ) { - pool[ i ].length = 0; - } - nbytes = 0; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6c12a4e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Typed array pool. -* -* @module @stdlib/array-pool -* -* @example -* var typedarraypool = require( '@stdlib/array-pool' ); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8f69ee3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,63 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @name typedarraypool -* @type {Function} -* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a valid array length or an array-like object -* @throws {TypeError} must provide a recognized data type -* @returns {(TypedArray|null)} typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -var typedarraypool = factory(); - - -// EXPORTS // - -module.exports = typedarraypool; diff --git a/lib/pool.js b/lib/pool.js deleted file mode 100644 index 5abd287..0000000 --- a/lib/pool.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Initializes a cache for pooled typed array buffers. -* -* @private -* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size -* @returns {ArrayArray} initialized cache -*/ -function pool( n ) { - var out; - var i; - - out = []; - for ( i = 0; i < n+1; i++ ) { - out.push( [] ); - } - return out; -} - - -// EXPORTS // - -module.exports = pool; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 4135ec9..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'highWaterMark': 1024 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '00d2h', options ) ); - } - if ( hasOwnProp( options, 'highWaterMark' ) ) { - opts.highWaterMark = options.highWaterMark; - if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( '00d35', 'highWaterMark', opts.highWaterMark ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 558fca7..42614cf 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Typed array pool.", "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,76 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.0.x", - "@stdlib/array-buffer": "^0.0.x", - "@stdlib/array-typed-ctors": "^0.0.x", - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-arraybuffer": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-complex128array": "^0.0.x", - "@stdlib/assert-is-complex64array": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/assert-is-typed-array-like": "^0.0.x", - "@stdlib/math-base-special-ceil": "^0.0.x", - "@stdlib/math-base-special-ceil2": "^0.0.x", - "@stdlib/math-base-special-floor": "^0.0.x", - "@stdlib/math-base-special-log2": "^0.0.x", - "@stdlib/math-base-special-min": "^0.0.x", - "@stdlib/strided-base-reinterpret-complex128": "^0.0.x", - "@stdlib/strided-base-reinterpret-complex64": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-copy": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.0.x", - "@stdlib/array-complex64": "^0.0.x", - "@stdlib/array-float32": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/array-int16": "^0.0.x", - "@stdlib/array-int32": "^0.0.x", - "@stdlib/array-int8": "^0.0.x", - "@stdlib/array-uint16": "^0.0.x", - "@stdlib/array-uint32": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/array-uint8c": "^0.0.x", - "@stdlib/assert-instance-of": "^0.0.x", - "@stdlib/assert-is-complex-typed-array": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-typed-array": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/complex-float32": "^0.0.x", - "@stdlib/complex-float64": "^0.0.x", - "@stdlib/complex-imag": "^0.0.x", - "@stdlib/complex-imagf": "^0.0.x", - "@stdlib/complex-real": "^0.0.x", - "@stdlib/complex-realf": "^0.0.x", - "@stdlib/math-base-special-pow": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..92a6d42 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 396aee2..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,2240 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function (no options)', function test( t ) { - t.strictEqual( typeof factory(), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - t.strictEqual( typeof factory( {} ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided a `highWaterMark` option which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (length)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a function which returns a typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, length)', function test( t ) { - var typedarraypool = factory(); - var arr; - - arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a `malloc` method which is a circular reference', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - var buf; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the returned function is a property which returns the pool\'s high water mark', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function supports specifying a high water mark which limits the total amount of memory a pool can allocate', function test( t ) { - var typedarraypool; - var arr1; - var arr2; - - typedarraypool = factory({ - 'highWaterMark': 64 // bytes - }); - - typedarraypool.clear(); - - arr1 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr1.length, 8, 'returns expected value' ); - t.strictEqual( arr1.byteLength, 64, 'returns expected value' ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - typedarraypool.free( arr1 ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Create an array which is less than or equal to the high water mark: - arr2 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr2.length, 8, 'returns expected value' ); - t.strictEqual( arr2.byteLength, 64, 'returns expected value' ); - - typedarraypool.free( arr2 ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a property which returns the total number of accumulated bytes', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var typedarraypool; - var arrs; - var i; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 54aa5ee..0000000 --- a/test/test.js +++ /dev/null @@ -1,1797 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var typedarraypool = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -}); From f24bb805730d752b3c3c7745177eaf17394a5439 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 18:51:38 +0000 Subject: [PATCH 008/103] Transform error messages --- lib/factory.js | 6 +++--- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 2401100..b75e403 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -33,7 +33,7 @@ var ctors = require( '@stdlib/array-typed-ctors' ); var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( '@stdlib/utils-copy' ); var ArrayBuffer = require( '@stdlib/array-buffer' ); var ceil = require( '@stdlib/math-base-special-ceil' ); @@ -226,7 +226,7 @@ function factory( options ) { } ctor = ctors( dtype ); if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '00d2k', dtype ) ); } if ( nargs <= 0 ) { return new ctor( 0 ); @@ -263,7 +263,7 @@ function factory( options ) { } return out; } - throw new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) ); + throw new TypeError( format( '00d33', arguments[ 0 ] ) ); } /** diff --git a/lib/validate.js b/lib/validate.js index ce54890..4135ec9 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '00d2h', options ) ); } if ( hasOwnProp( options, 'highWaterMark' ) ) { opts.highWaterMark = options.highWaterMark; if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) ); + return new TypeError( format( '00d35', 'highWaterMark', opts.highWaterMark ) ); } } return null; diff --git a/package.json b/package.json index 50986ed..558fca7 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "@stdlib/math-base-special-min": "^0.0.x", "@stdlib/strided-base-reinterpret-complex128": "^0.0.x", "@stdlib/strided-base-reinterpret-complex64": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-copy": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", From 3206061c4b6f89643bd9736d83de5cc3119e3798 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 19:23:58 +0000 Subject: [PATCH 009/103] Remove files --- index.d.ts | 359 ------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 3053 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 4500b91..0000000 --- a/index.d.ts +++ /dev/null @@ -1,359 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; -import ArrayBuffer = require( '@stdlib/array-buffer' ); - -/** -* Typed array or null. -*/ -type TypedArrayOrNull = RealOrComplexTypedArray | null; - -/** -* Interface defining pool options. -*/ -interface Options { - /** - * Maximum total memory which can be allocated. - */ - highWaterMark?: number; -} - -/** -* Pool interface. -*/ -interface Pool { - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr = typedarraypool(); - * // returns [] - * - * @example - * var arr = typedarraypool( 'float32' ); - * // returns [] - */ - ( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * // Allocate an array of doubles: - * var arr = typedarraypool( 5, 'float64' ); - * // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * typedarraypool.free( arr ); - * - * @example - * var arr1 = typedarraypool( [ 0.5, 0.5, 0.5 ] ); - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * @example - * var arr1 = [ 0.5, 0.5, 0.5 ]; - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - */ - ( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc(); - * // returns [] - * - * var arr2 = typedarraypool.calloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param length - typed array length - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc( 5 ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * var arr2 = typedarraypool.calloc( 5, 'uint8' ); - * // returns [ 0, 0, 0, 0, 0 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( length: number, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc(); - * // returns [] - * - * var arr2 = typedarraypool.malloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc( 5 ); - * // returns - * - * var arr2 = typedarraypool.malloc( 5, 'uint8' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 5.0, -3.0, 2.0 ] ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr2 = typedarraypool.malloc( arr1 ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr3 = typedarraypool.malloc( arr1, 'int32' ); - * // returns [ 5, -3, 2 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * typedarraypool.free( arr3 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ] ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * var arr2 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ], 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Frees a typed array or typed array buffer for use in a future allocation. - * - * @param buf - typed array or typed array buffer to free - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array for use in a future allocation: - * typedarraypool.free( arr ); - * - * // Create another typed array: - * arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array buffer for use in a future allocation: - * typedarraypool.free( arr.buffer ); - */ - free( buf: RealOrComplexTypedArray | ArrayBuffer ): void; - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr ); - * - * // ... - * - * // Clear all freed buffers: - * typedarraypool.clear(); - */ - clear(): void; - - /** - * Read-only property returning the pool's high water mark. - * - * ## Notes - * - * - Once a high water mark is reached, typed array allocation fails. - * - * @example - * var limit = typedarraypool.highWaterMark; - * // returns - */ - readonly highWaterMark: number; - - /** - * Read-only property returning the total number of allocated bytes. - * - * @example - * var arr = typedarraypool( 5, 'float64' ); - * - * var nbytes = typedarraypool.nbytes; - * // returns - */ - readonly nbytes: number; - - /** - * Creates a typed array pool. - * - * @param options - pool options - * @param options.highWaterMark - maximum total memory which can be allocated - * @throws must provide valid options - * @returns allocator - * - * @example - * var allocator = typedarraypool.factory(); - * - * // Allocate an array of doubles: - * var arr = allocator( 5, 'float64' ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * allocator.free( arr ); - */ - factory( options?: Options ): Pool; -} - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @param arg - an array length or an array-like object -* @param dtype - data type (default: 'float64') -* @returns typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -declare var typedarraypool: Pool; - - -// EXPORTS // - -export = typedarraypool; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index de19cff..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";var w={highWaterMark:9007199254740992};function M(e,t){return y(t)?k(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(f("00d35","highWaterMark",e.highWaterMark)):null:new TypeError(f("00d2h",t))}function W(e){var t,r;for(t=[],r=0;rL.highWaterMark?null:(t=new c(e),k+=e,t)}function z(e,t,r){var s;return 0===t?new e(0):null===(s=q(b(t)*E[r]))?s:new e(s,0,t)}function C(){var e,i,n,l,j,c,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(n=d(i)))throw new TypeError(f("00d2k",i));if(e<=0)return new n(0);if(r(arguments[0]))return z(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,m(l)?l=h(l,0):o(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=z(n,u,i)))return j;if(B(j)||A(j))return j.set(l),j;for(g=p(l).getter,c=p(j).setter,b=0;b0){for(t=u(v(e.byteLength)),t=x(T.length-1,t),r=T[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = copy( defaults );\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '00d2k', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring user's don't do ill-advised things...\n\t\t\tget = arraylike2object( arr ).getter;\n\t\t\tset = arraylike2object( out ).setter;\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '00d33', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool' ;\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","copy","defaults","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","arraylike2object","getter","setter","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;qpEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,QAAS,gBAAiBP,EAAKI,gBAGxD,KARC,IAAIE,UAAWC,EAAQ,QAASN,ICtBzC,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,kHCcJG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,EAUzB,SAASK,EAAiBD,GACzB,OAASA,aAAeF,EA8BzB,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EAAOsB,EAAMC,GACRC,UAAUC,SACdJ,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOkB,EAAYC,EAAMC,EAAM5B,EAAKI,iBACpCgB,EAAS,EAETS,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB9B,EAAKI,eAC3C8B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOf,EAUR,SAASgB,EAAa3B,GACrB,IAAI4B,EACA1B,EAMJ,OAHAA,EAAIiB,EAAMnB,IAGDD,EAAKiB,QAAUjB,EAAMG,GAAIc,OAC1BjB,EAAMG,GAAI2B,MAGblB,EAAOX,EAAIT,EAAKI,cACb,MAERiC,EAAM,IAAIE,EAAa9B,GAGvBW,GAAUX,EAEH4B,GAYR,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,GAmB1B,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAxB,EACAP,EACAqC,EACAC,EACAN,EACA/B,EAUJ,GALCgC,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAO3B,EAAO6B,IAEb,MAAM,IAAIrC,UAAWC,EAAQ,QAASoC,IAEvC,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKpC,EAAsBmB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAzB,EAAMO,UAAW,IACPC,OACL0B,EAAmBlC,GACvBA,EAAMmC,EAAgBnC,EAAK,GAChBoC,EAAkBpC,GAC7BA,EAAMqC,EAAerC,EAAK,GACf,WAAWsC,KAAMZ,KAE5BD,GAAO,GAGK,QADbhC,EAAM8B,EAAYC,EAAMC,EAAKC,IAE5B,OAAOjC,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAIqC,IAAK9B,GACFP,EAKR,IAFAsC,EAAMQ,EAAkBvC,GAAMwC,OAC9BV,EAAMS,EAAkB9C,GAAMgD,OACxB/C,EAAI,EAAGA,EAAI+B,EAAK/B,IACrBoC,EAAKrC,EAAKC,EAAGqC,EAAK/B,EAAKN,IAExB,OAAOD,EAER,MAAM,IAAIJ,UAAWC,EAAQ,QAASiB,UAAW,KAiBlD,SAASO,IACR,IAAIe,EACApC,EACAiD,EACAhD,EAUJ,GAAa,QANZD,EADc,KADfoC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCmC,EADIzC,EAAiBR,GACf0C,EAAgB1C,EAAK,GAChBM,EAAgBN,GACrB4C,EAAe5C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAIgD,EAAIlC,OAAQd,IAC5BgD,EAAKhD,GAAM,EAGb,OAAOD,EAeR,SAASsB,EAAMK,GACd,IAAI5B,EACAmD,EACAjD,EACJ,GAAKkD,EAAkBxB,IAASA,EAAIyB,OACnCzB,EAAMA,EAAIyB,YACJ,IAAMC,EAAe1B,GAC3B,MAAM,IAAI/B,UAAWC,EAAQ,4EAA6E8B,IAE3G,GAAKA,EAAI2B,WAAa,EAAI,CAQzB,IAPAvD,EAAIwD,EAAOrC,EAAMS,EAAI2B,aAGrBvD,EAAIyD,EAAK1D,EAAKiB,OAAO,EAAGhB,GAGxBmD,EAAIpD,EAAMC,GACJE,EAAI,EAAGA,EAAIiD,EAAEnC,OAAQd,IAC1B,GAAKiD,EAAGjD,KAAQ0B,EACf,OAAO,EAITuB,EAAEhD,KAAMyB,GAET,OAAO,EAQR,SAASJ,IACR,IAAItB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKiB,OAAQd,IAC7BH,EAAMG,GAAIc,OAAS,EAEpBL,EAAS,GCjTR,IAAC+C,EAAiBhD,ICPrBU,EAAAuC,EAAA,UAAAjD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 92a6d42..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 1c8986a1039967e4b6b2eefe67059f460725601f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 19:24:55 +0000 Subject: [PATCH 010/103] 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 | 43 +- benchmark/benchmark.calloc.js | 246 -- benchmark/benchmark.factory.js | 71 - benchmark/benchmark.js | 246 -- benchmark/benchmark.length.complex128.js | 102 - benchmark/benchmark.length.complex64.js | 102 - benchmark/benchmark.length.float32.js | 102 - benchmark/benchmark.length.float64.js | 102 - benchmark/benchmark.length.int16.js | 102 - benchmark/benchmark.length.int32.js | 102 - benchmark/benchmark.length.int8.js | 102 - benchmark/benchmark.length.uint16.js | 102 - benchmark/benchmark.length.uint32.js | 102 - benchmark/benchmark.length.uint8.js | 102 - benchmark/benchmark.length.uint8c.js | 102 - benchmark/benchmark.malloc.js | 246 -- branches.md | 53 - docs/repl.txt | 347 --- docs/types/test.ts | 193 -- examples/index.js | 80 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/bytes_per_element.json | 13 - lib/defaults.json | 3 - lib/factory.js | 370 --- lib/index.js | 56 - lib/main.js | 63 - lib/pool.js | 44 - lib/validate.js | 66 - package.json | 97 +- stats.html | 2689 +++++++++++++++++++++ test/test.factory.js | 2240 ----------------- test/test.js | 1797 -------------- 56 files changed, 2718 insertions(+), 10188 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.calloc.js delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.complex128.js delete mode 100644 benchmark/benchmark.length.complex64.js delete mode 100644 benchmark/benchmark.length.float32.js delete mode 100644 benchmark/benchmark.length.float64.js delete mode 100644 benchmark/benchmark.length.int16.js delete mode 100644 benchmark/benchmark.length.int32.js delete mode 100644 benchmark/benchmark.length.int8.js delete mode 100644 benchmark/benchmark.length.uint16.js delete mode 100644 benchmark/benchmark.length.uint32.js delete mode 100644 benchmark/benchmark.length.uint8.js delete mode 100644 benchmark/benchmark.length.uint8c.js delete mode 100644 benchmark/benchmark.malloc.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/bytes_per_element.json delete mode 100644 lib/defaults.json delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/pool.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ea35f20..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/array/pool) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 fc6d38a..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/array/pool) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -482,7 +481,7 @@ console.log( 'nbytes: %d', typedarray.nbytes ); ## 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]. @@ -548,7 +547,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm diff --git a/benchmark/benchmark.calloc.js b/benchmark/benchmark.calloc.js deleted file mode 100644 index e5a1c77..0000000 --- a/benchmark/benchmark.calloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':calloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index f7cd676..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = typedarray.factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:highWaterMark', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'highWaterMark': 0 - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.highWaterMark = i; - f = typedarray.factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a023d2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.complex128.js b/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 47b623b..0000000 --- a/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex64.js b/benchmark/benchmark.length.complex64.js deleted file mode 100644 index 40a412b..0000000 --- a/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float32.js b/benchmark/benchmark.length.float32.js deleted file mode 100644 index 0227ed7..0000000 --- a/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float64.js b/benchmark/benchmark.length.float64.js deleted file mode 100644 index 2dbac1c..0000000 --- a/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int16.js b/benchmark/benchmark.length.int16.js deleted file mode 100644 index e2a8adc..0000000 --- a/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int32.js b/benchmark/benchmark.length.int32.js deleted file mode 100644 index e4df0aa..0000000 --- a/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int8.js b/benchmark/benchmark.length.int8.js deleted file mode 100644 index 7ceac11..0000000 --- a/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint16.js b/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 9a532b6..0000000 --- a/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint32.js b/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 98f2d7f..0000000 --- a/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8.js b/benchmark/benchmark.length.uint8.js deleted file mode 100644 index 8359249..0000000 --- a/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8c.js b/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index d47d023..0000000 --- a/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.malloc.js b/benchmark/benchmark.malloc.js deleted file mode 100644 index d4eea72..0000000 --- a/benchmark/benchmark.malloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':malloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 8fce14f..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/array/pool" -click B href "https://github.com/stdlib-js/array-pool/tree/main" -click C href "https://github.com/stdlib-js/array-pool/tree/production" -click D href "https://github.com/stdlib-js/array-pool/tree/esm" -click E href "https://github.com/stdlib-js/array-pool/tree/deno" -click F href "https://github.com/stdlib-js/array-pool/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/pool -[production-url]: https://github.com/stdlib-js/array-pool/tree/production -[deno-url]: https://github.com/stdlib-js/array-pool/tree/deno -[umd-url]: https://github.com/stdlib-js/array-pool/tree/umd -[esm-url]: https://github.com/stdlib-js/array-pool/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5244595..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,347 +0,0 @@ - -{{alias}}( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - Memory is **uninitialized**, which means that the contents of a returned - typed array may contain sensitive contents. - - The function supports the following data types: - - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - The default typed array data type is `float64`. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}() - [] - > arr = {{alias}}( 'float32' ) - [] - - -{{alias}}( length[, dtype] ) - Returns an uninitialized typed array having a specified length from a typed - array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > arr = {{alias}}( 5, 'int32' ) - - - -{{alias}}( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - This method shares the same security vulnerabilities mentioned above. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc() - - > arr = {{alias}}.malloc( 'float32' ) - - - -{{alias}}.malloc( length[, dtype] ) - Returns a typed array having a specified length from a typed array memory - pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc( 5 ) - - > arr = {{alias}}.malloc( 5, 'int32' ) - - - -{{alias}}.malloc( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}.malloc( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.calloc( [dtype] ) - Returns a zero-initialized typed array from a typed array memory pool. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc() - [] - > arr = {{alias}}.calloc( 'float32' ) - [] - - -{{alias}}.calloc( length[, dtype] ) - Returns a zero-initialized typed array having a specified length from a - typed array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}.calloc( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}.free( buf ) - Frees a typed array or typed array buffer for use in a future allocation. - - Parameters - ---------- - buf: TypedArray|ArrayBuffer - Typed array or typed array buffer to free. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ) - - -{{alias}}.clear() - Clears the typed array pool allowing garbage collection of previously - allocated (and currently free) array buffers. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - > {{alias}}.clear() - - -{{alias}}.highWaterMark - Read-only property returning the pool's high water mark. - - Once a high water mark is reached, typed array allocation fails. - - Examples - -------- - > {{alias}}.highWaterMark - - -{{alias}}.nbytes - Read-only property returning the total number of allocated bytes. - - The returned value is the total accumulated value. Hence, anytime a pool - must allocate a new array buffer (i.e., more memory), the pool increments - this value. - - The only time this value is decremented is when a pool is cleared. - - This behavior means that, while allocated buffers which are never freed may, - in fact, be garbage collected, they continue to count against the high water - mark limit. - - Accordingly, you should *always* free allocated buffers in order to prevent - the pool from believing that non-freed buffers are continually in use. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.nbytes - - -{{alias}}.factory( [options] ) - Creates a typed array pool. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.highWaterMark: integer (optional) - Maximum total memory (in bytes) which can be allocated. - - Returns - ------- - fcn: Function - Function for creating typed arrays from a typed array memory pool. - - Examples - -------- - > var pool = {{alias}}.factory(); - > var arr1 = pool( 3, 'float64' ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1014bba..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,193 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-empty */ -/* tslint:disable:no-unused-expression */ - -import typedarraypool = require( './index' ); - - -// TESTS // - -// The function returns a typed array or null... -{ - typedarraypool(); // $ExpectType TypedArrayOrNull - typedarraypool( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the function is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool( true ); // $ExpectError - typedarraypool( false ); // $ExpectError - typedarraypool( null ); // $ExpectError - typedarraypool( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized data type... -{ - typedarraypool( 4, true ); // $ExpectError - typedarraypool( 4, false ); // $ExpectError - typedarraypool( 4, null ); // $ExpectError - typedarraypool( 4, 'abc' ); // $ExpectError - typedarraypool( 4, 123 ); // $ExpectError - typedarraypool( 4, [] ); // $ExpectError - typedarraypool( 4, {} ); // $ExpectError - typedarraypool( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an incorrect number of arguments... -{ - typedarraypool( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `malloc` method which returns a typed array or null... -{ - typedarraypool.malloc(); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.malloc( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `malloc` method is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool.malloc( true ); // $ExpectError - typedarraypool.malloc( false ); // $ExpectError - typedarraypool.malloc( null ); // $ExpectError - typedarraypool.malloc( {} ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.malloc( 4, true ); // $ExpectError - typedarraypool.malloc( 4, false ); // $ExpectError - typedarraypool.malloc( 4, null ); // $ExpectError - typedarraypool.malloc( 4, 'abc' ); // $ExpectError - typedarraypool.malloc( 4, 123 ); // $ExpectError - typedarraypool.malloc( 4, [] ); // $ExpectError - typedarraypool.malloc( 4, {} ); // $ExpectError - typedarraypool.malloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided an incorrect number of arguments... -{ - typedarraypool.malloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `calloc` method which returns a typed array or null... -{ - typedarraypool.calloc(); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `calloc` method is provided a first argument which is not a number... -{ - typedarraypool.calloc( 'abc' ); // $ExpectError - typedarraypool.calloc( true ); // $ExpectError - typedarraypool.calloc( false ); // $ExpectError - typedarraypool.calloc( null ); // $ExpectError - typedarraypool.calloc( {} ); // $ExpectError - typedarraypool.calloc( [] ); // $ExpectError - typedarraypool.calloc( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.calloc( 4, true ); // $ExpectError - typedarraypool.calloc( 4, false ); // $ExpectError - typedarraypool.calloc( 4, null ); // $ExpectError - typedarraypool.calloc( 4, 'abc' ); // $ExpectError - typedarraypool.calloc( 4, 123 ); // $ExpectError - typedarraypool.calloc( 4, [] ); // $ExpectError - typedarraypool.calloc( 4, {} ); // $ExpectError - typedarraypool.calloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided an incorrect number of arguments... -{ - typedarraypool.calloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `factory` method which returns a typed array pool.. -{ - typedarraypool.factory(); // $ExpectType Pool - typedarraypool.factory( { 'highWaterMark': 556 } ); // $ExpectType Pool -} - -// The compiler throws an error if the `factory` method is provided a `highWaterMark` option which is not a number... -{ - typedarraypool.factory( { 'highWaterMark': true } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': false } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': 'abc' } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': null } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': [] } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': {} } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an incorrect number of arguments... -{ - typedarraypool.factory( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` method which returns void... -{ - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.free( arr ); // $ExpectType void -} - -// The compiler throws an error if the `free` method is provided a first argument which is neither a typed array nor array buffer... -{ - typedarraypool.free( true ); // $ExpectError - typedarraypool.free( false ); // $ExpectError - typedarraypool.free( 123 ); // $ExpectError - typedarraypool.free( 'abc' ); // $ExpectError - typedarraypool.free( null ); // $ExpectError - typedarraypool.free( {} ); // $ExpectError - typedarraypool.free( ( x: number ): number => x ); // $ExpectError -} - -// Attached to the main export is a `clear` method which returns void... -{ - typedarraypool.clear(); // $ExpectType void -} - -// The compiler throws an error if the `clear` method is provided arguments... -{ - typedarraypool.clear( {} ); // $ExpectError - typedarraypool.clear( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `highWaterMark` property... -{ - typedarraypool.highWaterMark; // $ExpectType number -} - -// Attached to the main export is a `nbytes` property... -{ - typedarraypool.nbytes; // $ExpectType number -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 24a7846..0000000 --- a/examples/index.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 randu = require( '@stdlib/random-base-randu' ); -var typedarraypool = require( './../lib' ); - -// Create a typed array pool which can allocate at most 1GB: -var typedarray = typedarraypool.factory({ - 'highWaterMark': 1e9 -}); - -// Inspect the pool: -console.log( 'Max bytes: %d', typedarray.highWaterMark ); -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Allocate an array for storing double-precision floating-point numbers: -var arr1 = typedarray( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Fill the array... -var i; -for ( i = 0; i < arr1.length; i++ ) { - arr1[ i ] = randu(); -} - -// Inspect array contents: -console.log( arr1 ); - -// Free the array: -typedarray.free( arr1 ); - -// Allocate another array similar to the previous one: -var arr2 = typedarray( 5, 'float64' ); -// returns - -// Check that we have been returned a new typed array view: -console.log( arr2 === arr1 ); -// => false - -// Inspect array contents: -console.log( arr2 ); - -// Free the array: -typedarray.free( arr2 ); - -// Allocate an initialized array: -var arr3 = typedarray.calloc( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect array contents: -console.log( arr3 ); - -// Free the array: -typedarray.free( arr3 ); - -// Clear the pool: -typedarray.clear(); - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 239fcdc..4500b91 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; import ArrayBuffer = require( '@stdlib/array-buffer' ); diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..de19cff --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";var w={highWaterMark:9007199254740992};function M(e,t){return y(t)?k(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(f("00d35","highWaterMark",e.highWaterMark)):null:new TypeError(f("00d2h",t))}function W(e){var t,r;for(t=[],r=0;rL.highWaterMark?null:(t=new c(e),k+=e,t)}function z(e,t,r){var s;return 0===t?new e(0):null===(s=q(b(t)*E[r]))?s:new e(s,0,t)}function C(){var e,i,n,l,j,c,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(n=d(i)))throw new TypeError(f("00d2k",i));if(e<=0)return new n(0);if(r(arguments[0]))return z(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,m(l)?l=h(l,0):o(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=z(n,u,i)))return j;if(B(j)||A(j))return j.set(l),j;for(g=p(l).getter,c=p(j).setter,b=0;b0){for(t=u(v(e.byteLength)),t=x(T.length-1,t),r=T[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = copy( defaults );\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '00d2k', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring user's don't do ill-advised things...\n\t\t\tget = arraylike2object( arr ).getter;\n\t\t\tset = arraylike2object( out ).setter;\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '00d33', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool' ;\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","copy","defaults","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","arraylike2object","getter","setter","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;qpEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,QAAS,gBAAiBP,EAAKI,gBAGxD,KARC,IAAIE,UAAWC,EAAQ,QAASN,ICtBzC,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,kHCcJG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,EAUzB,SAASK,EAAiBD,GACzB,OAASA,aAAeF,EA8BzB,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EAAOsB,EAAMC,GACRC,UAAUC,SACdJ,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOkB,EAAYC,EAAMC,EAAM5B,EAAKI,iBACpCgB,EAAS,EAETS,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB9B,EAAKI,eAC3C8B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOf,EAUR,SAASgB,EAAa3B,GACrB,IAAI4B,EACA1B,EAMJ,OAHAA,EAAIiB,EAAMnB,IAGDD,EAAKiB,QAAUjB,EAAMG,GAAIc,OAC1BjB,EAAMG,GAAI2B,MAGblB,EAAOX,EAAIT,EAAKI,cACb,MAERiC,EAAM,IAAIE,EAAa9B,GAGvBW,GAAUX,EAEH4B,GAYR,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,GAmB1B,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAxB,EACAP,EACAqC,EACAC,EACAN,EACA/B,EAUJ,GALCgC,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAO3B,EAAO6B,IAEb,MAAM,IAAIrC,UAAWC,EAAQ,QAASoC,IAEvC,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKpC,EAAsBmB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAzB,EAAMO,UAAW,IACPC,OACL0B,EAAmBlC,GACvBA,EAAMmC,EAAgBnC,EAAK,GAChBoC,EAAkBpC,GAC7BA,EAAMqC,EAAerC,EAAK,GACf,WAAWsC,KAAMZ,KAE5BD,GAAO,GAGK,QADbhC,EAAM8B,EAAYC,EAAMC,EAAKC,IAE5B,OAAOjC,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAIqC,IAAK9B,GACFP,EAKR,IAFAsC,EAAMQ,EAAkBvC,GAAMwC,OAC9BV,EAAMS,EAAkB9C,GAAMgD,OACxB/C,EAAI,EAAGA,EAAI+B,EAAK/B,IACrBoC,EAAKrC,EAAKC,EAAGqC,EAAK/B,EAAKN,IAExB,OAAOD,EAER,MAAM,IAAIJ,UAAWC,EAAQ,QAASiB,UAAW,KAiBlD,SAASO,IACR,IAAIe,EACApC,EACAiD,EACAhD,EAUJ,GAAa,QANZD,EADc,KADfoC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCmC,EADIzC,EAAiBR,GACf0C,EAAgB1C,EAAK,GAChBM,EAAgBN,GACrB4C,EAAe5C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAIgD,EAAIlC,OAAQd,IAC5BgD,EAAKhD,GAAM,EAGb,OAAOD,EAeR,SAASsB,EAAMK,GACd,IAAI5B,EACAmD,EACAjD,EACJ,GAAKkD,EAAkBxB,IAASA,EAAIyB,OACnCzB,EAAMA,EAAIyB,YACJ,IAAMC,EAAe1B,GAC3B,MAAM,IAAI/B,UAAWC,EAAQ,4EAA6E8B,IAE3G,GAAKA,EAAI2B,WAAa,EAAI,CAQzB,IAPAvD,EAAIwD,EAAOrC,EAAMS,EAAI2B,aAGrBvD,EAAIyD,EAAK1D,EAAKiB,OAAO,EAAGhB,GAGxBmD,EAAIpD,EAAMC,GACJE,EAAI,EAAGA,EAAIiD,EAAEnC,OAAQd,IAC1B,GAAKiD,EAAGjD,KAAQ0B,EACf,OAAO,EAITuB,EAAEhD,KAAMyB,GAET,OAAO,EAQR,SAASJ,IACR,IAAItB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKiB,OAAQd,IAC7BH,EAAMG,GAAIc,OAAS,EAEpBL,EAAS,GCjTR,IAAC+C,EAAiBhD,ICPrBU,EAAAuC,EAAA,UAAAjD"} \ No newline at end of file diff --git a/lib/bytes_per_element.json b/lib/bytes_per_element.json deleted file mode 100644 index f97fe70..0000000 --- a/lib/bytes_per_element.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "float64": 8, - "float32": 4, - "int16": 2, - "int32": 4, - "int8": 1, - "uint16": 2, - "uint32": 4, - "uint8": 1, - "uint8c": 1, - "complex64": 8, - "complex128": 16 -} diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index c71c8f2..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "highWaterMark": 9007199254740992 -} diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index b75e403..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,370 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var isComplex64Array = require( '@stdlib/assert-is-complex64array' ); -var isComplex128Array = require( '@stdlib/assert-is-complex128array' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var ctors = require( '@stdlib/array-typed-ctors' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( '@stdlib/utils-copy' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil = require( '@stdlib/math-base-special-ceil' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); -var log2 = require( '@stdlib/math-base-special-log2' ); -var min = require( '@stdlib/math-base-special-min' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); -var createPool = require( './pool.js' ); -var BYTES_PER_ELEMENT = require( './bytes_per_element.json' ); - - -// VARIABLES // - -var Complex64Array = ctors( 'complex64' ); -var Complex128Array = ctors( 'complex128' ); - - -// FUNCTIONS // - -/** -* Tests whether an array is a single-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a single-precision complex floating-point number array -*/ -function isCmplx64Array( arr ) { - return ( arr instanceof Complex64Array ); -} - -/** -* Tests whether an array is a double-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a double-precision complex floating-point number array -*/ -function isCmplx128Array( arr ) { - return ( arr instanceof Complex128Array ); -} - - -// MAIN // - -/** -* Creates a typed array pool. -* -* @param {Options} [options] - pool options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} allocator -* -* @example -* var typedarraypool = factory(); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -function factory( options ) { - var nbytes; - var pool; - var opts; - var err; - - opts = copy( defaults ); - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - pool = createPool( ceil( log2( opts.highWaterMark ) ) ); - nbytes = 0; - - setReadOnly( malloc, 'malloc', malloc ); // circular reference - setReadOnly( malloc, 'calloc', calloc ); - setReadOnly( malloc, 'free', free ); - setReadOnly( malloc, 'clear', clear ); - setReadOnly( malloc, 'highWaterMark', opts.highWaterMark ); - setReadOnlyAccessor( malloc, 'nbytes', getBytes ); - - return malloc; - - /** - * Returns the number of allocated bytes. - * - * @private - * @returns {NonNegativeInteger} number of allocated bytes - */ - function getBytes() { - return nbytes; - } - - /** - * Returns an array buffer. - * - * @private - * @param {NonNegativeInteger} n - number of bytes - * @returns {(ArrayBuffer|null)} array buffer or null - */ - function arraybuffer( n ) { - var buf; - var i; - - // Convert the number of bytes to an index in our pool table: - i = log2( n ); - - // If we already have an available array buffer, use it... - if ( i < pool.length && pool[ i ].length ) { - return pool[ i ].pop(); - } - // Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate... - if ( nbytes+n > opts.highWaterMark ) { - return null; - } - buf = new ArrayBuffer( n ); - - // Update the running counter of allocated bytes: - nbytes += n; - - return buf; - } - - /** - * Returns a typed array. - * - * @private - * @param {Function} ctor - typed array constructor - * @param {NonNegativeInteger} len - view length - * @param {string} dtype - data type - * @returns {(TypedArray|null)} typed array or null - */ - function typedarray( ctor, len, dtype ) { - var buf; - if ( len === 0 ) { - return new ctor( 0 ); - } - buf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] ); - if ( buf === null ) { - return buf; - } - return new ctor( buf, 0, len ); - } - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length or an array-like object - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function malloc() { - var nargs; - var dtype; - var ctor; - var arr; - var out; - var set; - var get; - var len; - var i; - - nargs = arguments.length; - if ( nargs && isString( arguments[ nargs-1 ] ) ) { - nargs -= 1; - dtype = arguments[ nargs ]; - } else { - dtype = 'float64'; - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( '00d2k', dtype ) ); - } - if ( nargs <= 0 ) { - return new ctor( 0 ); - } - // Check if provided a typed array length... - if ( isNonNegativeInteger( arguments[ 0 ] ) ) { - return typedarray( ctor, arguments[ 0 ], dtype ); - } - // Check if provided an array-like object containing data elements... - if ( isCollection( arguments[ 0 ] ) ) { - arr = arguments[ 0 ]; - len = arr.length; - if ( isComplex128Array( arr ) ) { - arr = reinterpret128( arr, 0 ); - } else if ( isComplex64Array( arr ) ) { - arr = reinterpret64( arr, 0 ); - } else if ( /^complex/.test( dtype ) ) { - // Assume we've been provided an array of interleaved real and imaginary components... - len /= 2; - } - out = typedarray( ctor, len, dtype ); - if ( out === null ) { - return out; - } - if ( isCmplx128Array( out ) || isCmplx64Array( out ) ) { - out.set( arr ); - return out; - } - // Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other "unsafe" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring user's don't do ill-advised things... - get = arraylike2object( arr ).getter; - set = arraylike2object( out ).setter; - for ( i = 0; i < len; i++ ) { - set( out, i, get( arr, i ) ); - } - return out; - } - throw new TypeError( format( '00d33', arguments[ 0 ] ) ); - } - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {NonNegativeInteger} [len=0] - array length - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function calloc() { - var nargs; - var out; - var tmp; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - out = malloc(); - } else if ( nargs === 1 ) { - out = malloc( arguments[ 0 ] ); - } else { - out = malloc( arguments[ 0 ], arguments[ 1 ] ); - } - if ( out !== null ) { - // Initialize the memory... - if ( isCmplx128Array( out ) ) { - tmp = reinterpret128( out, 0 ); - } else if ( isCmplx64Array( out ) ) { - tmp = reinterpret64( out, 0 ); - } else { - tmp = out; - } - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = 0.0; - } - } - return out; - } - - /** - * Frees a typed array or typed array buffer. - * - * ## Notes - * - * - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., "freeing" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool. - * - * @private - * @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free - * @throws {TypeError} must provide a typed array or typed array buffer - * @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed - */ - function free( buf ) { - var n; - var p; - var i; - if ( isTypedArrayLike( buf ) && buf.buffer ) { - buf = buf.buffer; - } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) ); - } - if ( buf.byteLength > 0 ) { - n = floor( log2( buf.byteLength ) ); - - // Prohibit "freeing" array buffers which would potentially allow users to circumvent high water mark limits: - n = min( pool.length-1, n ); - - // Ensure that we do not attempt to free the same buffer more than once... - p = pool[ n ]; - for ( i = 0; i < p.length; i++ ) { - if ( p[ i ] === buf ) { - return false; - } - } - // Add the buffer to our pool of free buffers: - p.push( buf ); - } - return true; - } - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @private - */ - function clear() { - var i; - for ( i = 0; i < pool.length; i++ ) { - pool[ i ].length = 0; - } - nbytes = 0; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6c12a4e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Typed array pool. -* -* @module @stdlib/array-pool -* -* @example -* var typedarraypool = require( '@stdlib/array-pool' ); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8f69ee3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,63 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @name typedarraypool -* @type {Function} -* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a valid array length or an array-like object -* @throws {TypeError} must provide a recognized data type -* @returns {(TypedArray|null)} typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -var typedarraypool = factory(); - - -// EXPORTS // - -module.exports = typedarraypool; diff --git a/lib/pool.js b/lib/pool.js deleted file mode 100644 index 5abd287..0000000 --- a/lib/pool.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Initializes a cache for pooled typed array buffers. -* -* @private -* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size -* @returns {ArrayArray} initialized cache -*/ -function pool( n ) { - var out; - var i; - - out = []; - for ( i = 0; i < n+1; i++ ) { - out.push( [] ); - } - return out; -} - - -// EXPORTS // - -module.exports = pool; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 4135ec9..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'highWaterMark': 1024 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '00d2h', options ) ); - } - if ( hasOwnProp( options, 'highWaterMark' ) ) { - opts.highWaterMark = options.highWaterMark; - if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( '00d35', 'highWaterMark', opts.highWaterMark ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 558fca7..42614cf 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Typed array pool.", "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,76 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.0.x", - "@stdlib/array-buffer": "^0.0.x", - "@stdlib/array-typed-ctors": "^0.0.x", - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-arraybuffer": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-complex128array": "^0.0.x", - "@stdlib/assert-is-complex64array": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/assert-is-typed-array-like": "^0.0.x", - "@stdlib/math-base-special-ceil": "^0.0.x", - "@stdlib/math-base-special-ceil2": "^0.0.x", - "@stdlib/math-base-special-floor": "^0.0.x", - "@stdlib/math-base-special-log2": "^0.0.x", - "@stdlib/math-base-special-min": "^0.0.x", - "@stdlib/strided-base-reinterpret-complex128": "^0.0.x", - "@stdlib/strided-base-reinterpret-complex64": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-copy": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.0.x", - "@stdlib/array-complex64": "^0.0.x", - "@stdlib/array-float32": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/array-int16": "^0.0.x", - "@stdlib/array-int32": "^0.0.x", - "@stdlib/array-int8": "^0.0.x", - "@stdlib/array-uint16": "^0.0.x", - "@stdlib/array-uint32": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/array-uint8c": "^0.0.x", - "@stdlib/assert-instance-of": "^0.0.x", - "@stdlib/assert-is-complex-typed-array": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-typed-array": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/complex-float32": "^0.0.x", - "@stdlib/complex-float64": "^0.0.x", - "@stdlib/complex-imag": "^0.0.x", - "@stdlib/complex-imagf": "^0.0.x", - "@stdlib/complex-real": "^0.0.x", - "@stdlib/complex-realf": "^0.0.x", - "@stdlib/math-base-special-pow": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d3dda65 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 396aee2..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,2240 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function (no options)', function test( t ) { - t.strictEqual( typeof factory(), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - t.strictEqual( typeof factory( {} ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided a `highWaterMark` option which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (length)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a function which returns a typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, length)', function test( t ) { - var typedarraypool = factory(); - var arr; - - arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a `malloc` method which is a circular reference', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - var buf; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the returned function is a property which returns the pool\'s high water mark', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function supports specifying a high water mark which limits the total amount of memory a pool can allocate', function test( t ) { - var typedarraypool; - var arr1; - var arr2; - - typedarraypool = factory({ - 'highWaterMark': 64 // bytes - }); - - typedarraypool.clear(); - - arr1 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr1.length, 8, 'returns expected value' ); - t.strictEqual( arr1.byteLength, 64, 'returns expected value' ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - typedarraypool.free( arr1 ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Create an array which is less than or equal to the high water mark: - arr2 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr2.length, 8, 'returns expected value' ); - t.strictEqual( arr2.byteLength, 64, 'returns expected value' ); - - typedarraypool.free( arr2 ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a property which returns the total number of accumulated bytes', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var typedarraypool; - var arrs; - var i; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 54aa5ee..0000000 --- a/test/test.js +++ /dev/null @@ -1,1797 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var typedarraypool = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -}); From d63b458f711320bd26629c19d4e58053ee292761 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 03:58:27 +0000 Subject: [PATCH 011/103] Transform error messages --- lib/factory.js | 6 +++--- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 2401100..b75e403 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -33,7 +33,7 @@ var ctors = require( '@stdlib/array-typed-ctors' ); var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( '@stdlib/utils-copy' ); var ArrayBuffer = require( '@stdlib/array-buffer' ); var ceil = require( '@stdlib/math-base-special-ceil' ); @@ -226,7 +226,7 @@ function factory( options ) { } ctor = ctors( dtype ); if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '00d2k', dtype ) ); } if ( nargs <= 0 ) { return new ctor( 0 ); @@ -263,7 +263,7 @@ function factory( options ) { } return out; } - throw new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) ); + throw new TypeError( format( '00d33', arguments[ 0 ] ) ); } /** diff --git a/lib/validate.js b/lib/validate.js index ce54890..4135ec9 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '00d2h', options ) ); } if ( hasOwnProp( options, 'highWaterMark' ) ) { opts.highWaterMark = options.highWaterMark; if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) ); + return new TypeError( format( '00d35', 'highWaterMark', opts.highWaterMark ) ); } } return null; diff --git a/package.json b/package.json index 50986ed..558fca7 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "@stdlib/math-base-special-min": "^0.0.x", "@stdlib/strided-base-reinterpret-complex128": "^0.0.x", "@stdlib/strided-base-reinterpret-complex64": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-copy": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", From 3a0e6dc14176ea504317b247d1fc3b2e87954753 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 11:28:50 +0000 Subject: [PATCH 012/103] Remove files --- index.d.ts | 359 ------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 3053 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 4500b91..0000000 --- a/index.d.ts +++ /dev/null @@ -1,359 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; -import ArrayBuffer = require( '@stdlib/array-buffer' ); - -/** -* Typed array or null. -*/ -type TypedArrayOrNull = RealOrComplexTypedArray | null; - -/** -* Interface defining pool options. -*/ -interface Options { - /** - * Maximum total memory which can be allocated. - */ - highWaterMark?: number; -} - -/** -* Pool interface. -*/ -interface Pool { - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr = typedarraypool(); - * // returns [] - * - * @example - * var arr = typedarraypool( 'float32' ); - * // returns [] - */ - ( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * // Allocate an array of doubles: - * var arr = typedarraypool( 5, 'float64' ); - * // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * typedarraypool.free( arr ); - * - * @example - * var arr1 = typedarraypool( [ 0.5, 0.5, 0.5 ] ); - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * @example - * var arr1 = [ 0.5, 0.5, 0.5 ]; - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - */ - ( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc(); - * // returns [] - * - * var arr2 = typedarraypool.calloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param length - typed array length - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc( 5 ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * var arr2 = typedarraypool.calloc( 5, 'uint8' ); - * // returns [ 0, 0, 0, 0, 0 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( length: number, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc(); - * // returns [] - * - * var arr2 = typedarraypool.malloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc( 5 ); - * // returns - * - * var arr2 = typedarraypool.malloc( 5, 'uint8' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 5.0, -3.0, 2.0 ] ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr2 = typedarraypool.malloc( arr1 ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr3 = typedarraypool.malloc( arr1, 'int32' ); - * // returns [ 5, -3, 2 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * typedarraypool.free( arr3 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ] ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * var arr2 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ], 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Frees a typed array or typed array buffer for use in a future allocation. - * - * @param buf - typed array or typed array buffer to free - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array for use in a future allocation: - * typedarraypool.free( arr ); - * - * // Create another typed array: - * arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array buffer for use in a future allocation: - * typedarraypool.free( arr.buffer ); - */ - free( buf: RealOrComplexTypedArray | ArrayBuffer ): void; - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr ); - * - * // ... - * - * // Clear all freed buffers: - * typedarraypool.clear(); - */ - clear(): void; - - /** - * Read-only property returning the pool's high water mark. - * - * ## Notes - * - * - Once a high water mark is reached, typed array allocation fails. - * - * @example - * var limit = typedarraypool.highWaterMark; - * // returns - */ - readonly highWaterMark: number; - - /** - * Read-only property returning the total number of allocated bytes. - * - * @example - * var arr = typedarraypool( 5, 'float64' ); - * - * var nbytes = typedarraypool.nbytes; - * // returns - */ - readonly nbytes: number; - - /** - * Creates a typed array pool. - * - * @param options - pool options - * @param options.highWaterMark - maximum total memory which can be allocated - * @throws must provide valid options - * @returns allocator - * - * @example - * var allocator = typedarraypool.factory(); - * - * // Allocate an array of doubles: - * var arr = allocator( 5, 'float64' ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * allocator.free( arr ); - */ - factory( options?: Options ): Pool; -} - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @param arg - an array length or an array-like object -* @param dtype - data type (default: 'float64') -* @returns typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -declare var typedarraypool: Pool; - - -// EXPORTS // - -export = typedarraypool; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index de19cff..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";var w={highWaterMark:9007199254740992};function M(e,t){return y(t)?k(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(f("00d35","highWaterMark",e.highWaterMark)):null:new TypeError(f("00d2h",t))}function W(e){var t,r;for(t=[],r=0;rL.highWaterMark?null:(t=new c(e),k+=e,t)}function z(e,t,r){var s;return 0===t?new e(0):null===(s=q(b(t)*E[r]))?s:new e(s,0,t)}function C(){var e,i,n,l,j,c,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(n=d(i)))throw new TypeError(f("00d2k",i));if(e<=0)return new n(0);if(r(arguments[0]))return z(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,m(l)?l=h(l,0):o(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=z(n,u,i)))return j;if(B(j)||A(j))return j.set(l),j;for(g=p(l).getter,c=p(j).setter,b=0;b0){for(t=u(v(e.byteLength)),t=x(T.length-1,t),r=T[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = copy( defaults );\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '00d2k', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring user's don't do ill-advised things...\n\t\t\tget = arraylike2object( arr ).getter;\n\t\t\tset = arraylike2object( out ).setter;\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '00d33', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool' ;\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","copy","defaults","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","arraylike2object","getter","setter","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;qpEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,QAAS,gBAAiBP,EAAKI,gBAGxD,KARC,IAAIE,UAAWC,EAAQ,QAASN,ICtBzC,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,kHCcJG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,EAUzB,SAASK,EAAiBD,GACzB,OAASA,aAAeF,EA8BzB,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EAAOsB,EAAMC,GACRC,UAAUC,SACdJ,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOkB,EAAYC,EAAMC,EAAM5B,EAAKI,iBACpCgB,EAAS,EAETS,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB9B,EAAKI,eAC3C8B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOf,EAUR,SAASgB,EAAa3B,GACrB,IAAI4B,EACA1B,EAMJ,OAHAA,EAAIiB,EAAMnB,IAGDD,EAAKiB,QAAUjB,EAAMG,GAAIc,OAC1BjB,EAAMG,GAAI2B,MAGblB,EAAOX,EAAIT,EAAKI,cACb,MAERiC,EAAM,IAAIE,EAAa9B,GAGvBW,GAAUX,EAEH4B,GAYR,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,GAmB1B,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAxB,EACAP,EACAqC,EACAC,EACAN,EACA/B,EAUJ,GALCgC,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAO3B,EAAO6B,IAEb,MAAM,IAAIrC,UAAWC,EAAQ,QAASoC,IAEvC,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKpC,EAAsBmB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAzB,EAAMO,UAAW,IACPC,OACL0B,EAAmBlC,GACvBA,EAAMmC,EAAgBnC,EAAK,GAChBoC,EAAkBpC,GAC7BA,EAAMqC,EAAerC,EAAK,GACf,WAAWsC,KAAMZ,KAE5BD,GAAO,GAGK,QADbhC,EAAM8B,EAAYC,EAAMC,EAAKC,IAE5B,OAAOjC,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAIqC,IAAK9B,GACFP,EAKR,IAFAsC,EAAMQ,EAAkBvC,GAAMwC,OAC9BV,EAAMS,EAAkB9C,GAAMgD,OACxB/C,EAAI,EAAGA,EAAI+B,EAAK/B,IACrBoC,EAAKrC,EAAKC,EAAGqC,EAAK/B,EAAKN,IAExB,OAAOD,EAER,MAAM,IAAIJ,UAAWC,EAAQ,QAASiB,UAAW,KAiBlD,SAASO,IACR,IAAIe,EACApC,EACAiD,EACAhD,EAUJ,GAAa,QANZD,EADc,KADfoC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCmC,EADIzC,EAAiBR,GACf0C,EAAgB1C,EAAK,GAChBM,EAAgBN,GACrB4C,EAAe5C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAIgD,EAAIlC,OAAQd,IAC5BgD,EAAKhD,GAAM,EAGb,OAAOD,EAeR,SAASsB,EAAMK,GACd,IAAI5B,EACAmD,EACAjD,EACJ,GAAKkD,EAAkBxB,IAASA,EAAIyB,OACnCzB,EAAMA,EAAIyB,YACJ,IAAMC,EAAe1B,GAC3B,MAAM,IAAI/B,UAAWC,EAAQ,4EAA6E8B,IAE3G,GAAKA,EAAI2B,WAAa,EAAI,CAQzB,IAPAvD,EAAIwD,EAAOrC,EAAMS,EAAI2B,aAGrBvD,EAAIyD,EAAK1D,EAAKiB,OAAO,EAAGhB,GAGxBmD,EAAIpD,EAAMC,GACJE,EAAI,EAAGA,EAAIiD,EAAEnC,OAAQd,IAC1B,GAAKiD,EAAGjD,KAAQ0B,EACf,OAAO,EAITuB,EAAEhD,KAAMyB,GAET,OAAO,EAQR,SAASJ,IACR,IAAItB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKiB,OAAQd,IAC7BH,EAAMG,GAAIc,OAAS,EAEpBL,EAAS,GCjTR,IAAC+C,EAAiBhD,ICPrBU,EAAAuC,EAAA,UAAAjD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d3dda65..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From d644bd698d54eff3568ca69f0d608024769e6615 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 11:29:36 +0000 Subject: [PATCH 013/103] 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 | 43 +- benchmark/benchmark.calloc.js | 246 -- benchmark/benchmark.factory.js | 71 - benchmark/benchmark.js | 246 -- benchmark/benchmark.length.complex128.js | 102 - benchmark/benchmark.length.complex64.js | 102 - benchmark/benchmark.length.float32.js | 102 - benchmark/benchmark.length.float64.js | 102 - benchmark/benchmark.length.int16.js | 102 - benchmark/benchmark.length.int32.js | 102 - benchmark/benchmark.length.int8.js | 102 - benchmark/benchmark.length.uint16.js | 102 - benchmark/benchmark.length.uint32.js | 102 - benchmark/benchmark.length.uint8.js | 102 - benchmark/benchmark.length.uint8c.js | 102 - benchmark/benchmark.malloc.js | 246 -- branches.md | 53 - docs/repl.txt | 347 --- docs/types/test.ts | 193 -- examples/index.js | 80 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/bytes_per_element.json | 13 - lib/defaults.json | 3 - lib/factory.js | 370 --- lib/index.js | 56 - lib/main.js | 63 - lib/pool.js | 44 - lib/validate.js | 66 - package.json | 97 +- stats.html | 2689 +++++++++++++++++++++ test/test.factory.js | 2240 ----------------- test/test.js | 1797 -------------- 57 files changed, 2718 insertions(+), 10262 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.calloc.js delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.complex128.js delete mode 100644 benchmark/benchmark.length.complex64.js delete mode 100644 benchmark/benchmark.length.float32.js delete mode 100644 benchmark/benchmark.length.float64.js delete mode 100644 benchmark/benchmark.length.int16.js delete mode 100644 benchmark/benchmark.length.int32.js delete mode 100644 benchmark/benchmark.length.int8.js delete mode 100644 benchmark/benchmark.length.uint16.js delete mode 100644 benchmark/benchmark.length.uint32.js delete mode 100644 benchmark/benchmark.length.uint8.js delete mode 100644 benchmark/benchmark.length.uint8c.js delete mode 100644 benchmark/benchmark.malloc.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/bytes_per_element.json delete mode 100644 lib/defaults.json delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/pool.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 705d042..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-08-01T01:45:13.814Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ea35f20..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/array/pool) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 fc6d38a..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/array/pool) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -482,7 +481,7 @@ console.log( 'nbytes: %d', typedarray.nbytes ); ## 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]. @@ -548,7 +547,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm diff --git a/benchmark/benchmark.calloc.js b/benchmark/benchmark.calloc.js deleted file mode 100644 index e5a1c77..0000000 --- a/benchmark/benchmark.calloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':calloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index f7cd676..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = typedarray.factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:highWaterMark', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'highWaterMark': 0 - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.highWaterMark = i; - f = typedarray.factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a023d2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.complex128.js b/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 47b623b..0000000 --- a/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex64.js b/benchmark/benchmark.length.complex64.js deleted file mode 100644 index 40a412b..0000000 --- a/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float32.js b/benchmark/benchmark.length.float32.js deleted file mode 100644 index 0227ed7..0000000 --- a/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float64.js b/benchmark/benchmark.length.float64.js deleted file mode 100644 index 2dbac1c..0000000 --- a/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int16.js b/benchmark/benchmark.length.int16.js deleted file mode 100644 index e2a8adc..0000000 --- a/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int32.js b/benchmark/benchmark.length.int32.js deleted file mode 100644 index e4df0aa..0000000 --- a/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int8.js b/benchmark/benchmark.length.int8.js deleted file mode 100644 index 7ceac11..0000000 --- a/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint16.js b/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 9a532b6..0000000 --- a/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint32.js b/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 98f2d7f..0000000 --- a/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8.js b/benchmark/benchmark.length.uint8.js deleted file mode 100644 index 8359249..0000000 --- a/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8c.js b/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index d47d023..0000000 --- a/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.malloc.js b/benchmark/benchmark.malloc.js deleted file mode 100644 index d4eea72..0000000 --- a/benchmark/benchmark.malloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':malloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 8fce14f..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/array/pool" -click B href "https://github.com/stdlib-js/array-pool/tree/main" -click C href "https://github.com/stdlib-js/array-pool/tree/production" -click D href "https://github.com/stdlib-js/array-pool/tree/esm" -click E href "https://github.com/stdlib-js/array-pool/tree/deno" -click F href "https://github.com/stdlib-js/array-pool/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/pool -[production-url]: https://github.com/stdlib-js/array-pool/tree/production -[deno-url]: https://github.com/stdlib-js/array-pool/tree/deno -[umd-url]: https://github.com/stdlib-js/array-pool/tree/umd -[esm-url]: https://github.com/stdlib-js/array-pool/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5244595..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,347 +0,0 @@ - -{{alias}}( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - Memory is **uninitialized**, which means that the contents of a returned - typed array may contain sensitive contents. - - The function supports the following data types: - - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - The default typed array data type is `float64`. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}() - [] - > arr = {{alias}}( 'float32' ) - [] - - -{{alias}}( length[, dtype] ) - Returns an uninitialized typed array having a specified length from a typed - array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > arr = {{alias}}( 5, 'int32' ) - - - -{{alias}}( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - This method shares the same security vulnerabilities mentioned above. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc() - - > arr = {{alias}}.malloc( 'float32' ) - - - -{{alias}}.malloc( length[, dtype] ) - Returns a typed array having a specified length from a typed array memory - pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc( 5 ) - - > arr = {{alias}}.malloc( 5, 'int32' ) - - - -{{alias}}.malloc( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}.malloc( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.calloc( [dtype] ) - Returns a zero-initialized typed array from a typed array memory pool. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc() - [] - > arr = {{alias}}.calloc( 'float32' ) - [] - - -{{alias}}.calloc( length[, dtype] ) - Returns a zero-initialized typed array having a specified length from a - typed array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}.calloc( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}.free( buf ) - Frees a typed array or typed array buffer for use in a future allocation. - - Parameters - ---------- - buf: TypedArray|ArrayBuffer - Typed array or typed array buffer to free. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ) - - -{{alias}}.clear() - Clears the typed array pool allowing garbage collection of previously - allocated (and currently free) array buffers. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - > {{alias}}.clear() - - -{{alias}}.highWaterMark - Read-only property returning the pool's high water mark. - - Once a high water mark is reached, typed array allocation fails. - - Examples - -------- - > {{alias}}.highWaterMark - - -{{alias}}.nbytes - Read-only property returning the total number of allocated bytes. - - The returned value is the total accumulated value. Hence, anytime a pool - must allocate a new array buffer (i.e., more memory), the pool increments - this value. - - The only time this value is decremented is when a pool is cleared. - - This behavior means that, while allocated buffers which are never freed may, - in fact, be garbage collected, they continue to count against the high water - mark limit. - - Accordingly, you should *always* free allocated buffers in order to prevent - the pool from believing that non-freed buffers are continually in use. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.nbytes - - -{{alias}}.factory( [options] ) - Creates a typed array pool. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.highWaterMark: integer (optional) - Maximum total memory (in bytes) which can be allocated. - - Returns - ------- - fcn: Function - Function for creating typed arrays from a typed array memory pool. - - Examples - -------- - > var pool = {{alias}}.factory(); - > var arr1 = pool( 3, 'float64' ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1014bba..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,193 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-empty */ -/* tslint:disable:no-unused-expression */ - -import typedarraypool = require( './index' ); - - -// TESTS // - -// The function returns a typed array or null... -{ - typedarraypool(); // $ExpectType TypedArrayOrNull - typedarraypool( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the function is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool( true ); // $ExpectError - typedarraypool( false ); // $ExpectError - typedarraypool( null ); // $ExpectError - typedarraypool( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized data type... -{ - typedarraypool( 4, true ); // $ExpectError - typedarraypool( 4, false ); // $ExpectError - typedarraypool( 4, null ); // $ExpectError - typedarraypool( 4, 'abc' ); // $ExpectError - typedarraypool( 4, 123 ); // $ExpectError - typedarraypool( 4, [] ); // $ExpectError - typedarraypool( 4, {} ); // $ExpectError - typedarraypool( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an incorrect number of arguments... -{ - typedarraypool( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `malloc` method which returns a typed array or null... -{ - typedarraypool.malloc(); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.malloc( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `malloc` method is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool.malloc( true ); // $ExpectError - typedarraypool.malloc( false ); // $ExpectError - typedarraypool.malloc( null ); // $ExpectError - typedarraypool.malloc( {} ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.malloc( 4, true ); // $ExpectError - typedarraypool.malloc( 4, false ); // $ExpectError - typedarraypool.malloc( 4, null ); // $ExpectError - typedarraypool.malloc( 4, 'abc' ); // $ExpectError - typedarraypool.malloc( 4, 123 ); // $ExpectError - typedarraypool.malloc( 4, [] ); // $ExpectError - typedarraypool.malloc( 4, {} ); // $ExpectError - typedarraypool.malloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided an incorrect number of arguments... -{ - typedarraypool.malloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `calloc` method which returns a typed array or null... -{ - typedarraypool.calloc(); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `calloc` method is provided a first argument which is not a number... -{ - typedarraypool.calloc( 'abc' ); // $ExpectError - typedarraypool.calloc( true ); // $ExpectError - typedarraypool.calloc( false ); // $ExpectError - typedarraypool.calloc( null ); // $ExpectError - typedarraypool.calloc( {} ); // $ExpectError - typedarraypool.calloc( [] ); // $ExpectError - typedarraypool.calloc( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.calloc( 4, true ); // $ExpectError - typedarraypool.calloc( 4, false ); // $ExpectError - typedarraypool.calloc( 4, null ); // $ExpectError - typedarraypool.calloc( 4, 'abc' ); // $ExpectError - typedarraypool.calloc( 4, 123 ); // $ExpectError - typedarraypool.calloc( 4, [] ); // $ExpectError - typedarraypool.calloc( 4, {} ); // $ExpectError - typedarraypool.calloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided an incorrect number of arguments... -{ - typedarraypool.calloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `factory` method which returns a typed array pool.. -{ - typedarraypool.factory(); // $ExpectType Pool - typedarraypool.factory( { 'highWaterMark': 556 } ); // $ExpectType Pool -} - -// The compiler throws an error if the `factory` method is provided a `highWaterMark` option which is not a number... -{ - typedarraypool.factory( { 'highWaterMark': true } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': false } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': 'abc' } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': null } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': [] } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': {} } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an incorrect number of arguments... -{ - typedarraypool.factory( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` method which returns void... -{ - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.free( arr ); // $ExpectType void -} - -// The compiler throws an error if the `free` method is provided a first argument which is neither a typed array nor array buffer... -{ - typedarraypool.free( true ); // $ExpectError - typedarraypool.free( false ); // $ExpectError - typedarraypool.free( 123 ); // $ExpectError - typedarraypool.free( 'abc' ); // $ExpectError - typedarraypool.free( null ); // $ExpectError - typedarraypool.free( {} ); // $ExpectError - typedarraypool.free( ( x: number ): number => x ); // $ExpectError -} - -// Attached to the main export is a `clear` method which returns void... -{ - typedarraypool.clear(); // $ExpectType void -} - -// The compiler throws an error if the `clear` method is provided arguments... -{ - typedarraypool.clear( {} ); // $ExpectError - typedarraypool.clear( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `highWaterMark` property... -{ - typedarraypool.highWaterMark; // $ExpectType number -} - -// Attached to the main export is a `nbytes` property... -{ - typedarraypool.nbytes; // $ExpectType number -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 24a7846..0000000 --- a/examples/index.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 randu = require( '@stdlib/random-base-randu' ); -var typedarraypool = require( './../lib' ); - -// Create a typed array pool which can allocate at most 1GB: -var typedarray = typedarraypool.factory({ - 'highWaterMark': 1e9 -}); - -// Inspect the pool: -console.log( 'Max bytes: %d', typedarray.highWaterMark ); -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Allocate an array for storing double-precision floating-point numbers: -var arr1 = typedarray( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Fill the array... -var i; -for ( i = 0; i < arr1.length; i++ ) { - arr1[ i ] = randu(); -} - -// Inspect array contents: -console.log( arr1 ); - -// Free the array: -typedarray.free( arr1 ); - -// Allocate another array similar to the previous one: -var arr2 = typedarray( 5, 'float64' ); -// returns - -// Check that we have been returned a new typed array view: -console.log( arr2 === arr1 ); -// => false - -// Inspect array contents: -console.log( arr2 ); - -// Free the array: -typedarray.free( arr2 ); - -// Allocate an initialized array: -var arr3 = typedarray.calloc( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect array contents: -console.log( arr3 ); - -// Free the array: -typedarray.free( arr3 ); - -// Clear the pool: -typedarray.clear(); - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 239fcdc..4500b91 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; import ArrayBuffer = require( '@stdlib/array-buffer' ); diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..55d247f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";var w={highWaterMark:9007199254740992};function M(e,t){return y(t)?k(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(f("00d35","highWaterMark",e.highWaterMark)):null:new TypeError(f("00d2h",t))}function W(e){var t,r;for(t=[],r=0;rL.highWaterMark?null:(t=new c(e),k+=e,t)}function z(e,t,r){var s;return 0===t?new e(0):null===(s=q(b(t)*E[r]))?s:new e(s,0,t)}function C(){var e,i,n,l,j,c,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(n=d(i)))throw new TypeError(f("00d2k",i));if(e<=0)return new n(0);if(r(arguments[0]))return z(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,m(l)?l=h(l,0):o(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=z(n,u,i)))return j;if(B(j)||A(j))return j.set(l),j;for(g=p(l).getter,c=p(j).setter,b=0;b0){for(t=u(v(e.byteLength)),t=x(T.length-1,t),r=T[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = copy( defaults );\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '00d2k', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring user's don't do ill-advised things...\n\t\t\tget = arraylike2object( arr ).getter;\n\t\t\tset = arraylike2object( out ).setter;\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '00d33', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool' ;\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","copy","defaults","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","arraylike2object","getter","setter","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;4pEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,QAAS,gBAAiBP,EAAKI,gBAGxD,KARC,IAAIE,UAAWC,EAAQ,QAASN,ICtBzC,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,kHCcJG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,EAUzB,SAASK,EAAiBD,GACzB,OAASA,aAAeF,EA8BzB,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EAAOsB,EAAMC,GACRC,UAAUC,SACdJ,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOkB,EAAYC,EAAMC,EAAM5B,EAAKI,iBACpCgB,EAAS,EAETS,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB9B,EAAKI,eAC3C8B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOf,EAUR,SAASgB,EAAa3B,GACrB,IAAI4B,EACA1B,EAMJ,OAHAA,EAAIiB,EAAMnB,IAGDD,EAAKiB,QAAUjB,EAAMG,GAAIc,OAC1BjB,EAAMG,GAAI2B,MAGblB,EAAOX,EAAIT,EAAKI,cACb,MAERiC,EAAM,IAAIE,EAAa9B,GAGvBW,GAAUX,EAEH4B,GAYR,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,GAmB1B,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAxB,EACAP,EACAqC,EACAC,EACAN,EACA/B,EAUJ,GALCgC,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAO3B,EAAO6B,IAEb,MAAM,IAAIrC,UAAWC,EAAQ,QAASoC,IAEvC,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKpC,EAAsBmB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAzB,EAAMO,UAAW,IACPC,OACL0B,EAAmBlC,GACvBA,EAAMmC,EAAgBnC,EAAK,GAChBoC,EAAkBpC,GAC7BA,EAAMqC,EAAerC,EAAK,GACf,WAAWsC,KAAMZ,KAE5BD,GAAO,GAGK,QADbhC,EAAM8B,EAAYC,EAAMC,EAAKC,IAE5B,OAAOjC,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAIqC,IAAK9B,GACFP,EAKR,IAFAsC,EAAMQ,EAAkBvC,GAAMwC,OAC9BV,EAAMS,EAAkB9C,GAAMgD,OACxB/C,EAAI,EAAGA,EAAI+B,EAAK/B,IACrBoC,EAAKrC,EAAKC,EAAGqC,EAAK/B,EAAKN,IAExB,OAAOD,EAER,MAAM,IAAIJ,UAAWC,EAAQ,QAASiB,UAAW,KAiBlD,SAASO,IACR,IAAIe,EACApC,EACAiD,EACAhD,EAUJ,GAAa,QANZD,EADc,KADfoC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCmC,EADIzC,EAAiBR,GACf0C,EAAgB1C,EAAK,GAChBM,EAAgBN,GACrB4C,EAAe5C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAIgD,EAAIlC,OAAQd,IAC5BgD,EAAKhD,GAAM,EAGb,OAAOD,EAeR,SAASsB,EAAMK,GACd,IAAI5B,EACAmD,EACAjD,EACJ,GAAKkD,EAAkBxB,IAASA,EAAIyB,OACnCzB,EAAMA,EAAIyB,YACJ,IAAMC,EAAe1B,GAC3B,MAAM,IAAI/B,UAAWC,EAAQ,4EAA6E8B,IAE3G,GAAKA,EAAI2B,WAAa,EAAI,CAQzB,IAPAvD,EAAIwD,EAAOrC,EAAMS,EAAI2B,aAGrBvD,EAAIyD,EAAK1D,EAAKiB,OAAO,EAAGhB,GAGxBmD,EAAIpD,EAAMC,GACJE,EAAI,EAAGA,EAAIiD,EAAEnC,OAAQd,IAC1B,GAAKiD,EAAGjD,KAAQ0B,EACf,OAAO,EAITuB,EAAEhD,KAAMyB,GAET,OAAO,EAQR,SAASJ,IACR,IAAItB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKiB,OAAQd,IAC7BH,EAAMG,GAAIc,OAAS,EAEpBL,EAAS,GCjTR,IAAC+C,EAAiBhD,ICPrBU,EAAAuC,EAAA,UAAAjD"} \ No newline at end of file diff --git a/lib/bytes_per_element.json b/lib/bytes_per_element.json deleted file mode 100644 index f97fe70..0000000 --- a/lib/bytes_per_element.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "float64": 8, - "float32": 4, - "int16": 2, - "int32": 4, - "int8": 1, - "uint16": 2, - "uint32": 4, - "uint8": 1, - "uint8c": 1, - "complex64": 8, - "complex128": 16 -} diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index c71c8f2..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "highWaterMark": 9007199254740992 -} diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index b75e403..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,370 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var isComplex64Array = require( '@stdlib/assert-is-complex64array' ); -var isComplex128Array = require( '@stdlib/assert-is-complex128array' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var ctors = require( '@stdlib/array-typed-ctors' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( '@stdlib/utils-copy' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil = require( '@stdlib/math-base-special-ceil' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); -var log2 = require( '@stdlib/math-base-special-log2' ); -var min = require( '@stdlib/math-base-special-min' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); -var createPool = require( './pool.js' ); -var BYTES_PER_ELEMENT = require( './bytes_per_element.json' ); - - -// VARIABLES // - -var Complex64Array = ctors( 'complex64' ); -var Complex128Array = ctors( 'complex128' ); - - -// FUNCTIONS // - -/** -* Tests whether an array is a single-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a single-precision complex floating-point number array -*/ -function isCmplx64Array( arr ) { - return ( arr instanceof Complex64Array ); -} - -/** -* Tests whether an array is a double-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a double-precision complex floating-point number array -*/ -function isCmplx128Array( arr ) { - return ( arr instanceof Complex128Array ); -} - - -// MAIN // - -/** -* Creates a typed array pool. -* -* @param {Options} [options] - pool options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} allocator -* -* @example -* var typedarraypool = factory(); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -function factory( options ) { - var nbytes; - var pool; - var opts; - var err; - - opts = copy( defaults ); - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - pool = createPool( ceil( log2( opts.highWaterMark ) ) ); - nbytes = 0; - - setReadOnly( malloc, 'malloc', malloc ); // circular reference - setReadOnly( malloc, 'calloc', calloc ); - setReadOnly( malloc, 'free', free ); - setReadOnly( malloc, 'clear', clear ); - setReadOnly( malloc, 'highWaterMark', opts.highWaterMark ); - setReadOnlyAccessor( malloc, 'nbytes', getBytes ); - - return malloc; - - /** - * Returns the number of allocated bytes. - * - * @private - * @returns {NonNegativeInteger} number of allocated bytes - */ - function getBytes() { - return nbytes; - } - - /** - * Returns an array buffer. - * - * @private - * @param {NonNegativeInteger} n - number of bytes - * @returns {(ArrayBuffer|null)} array buffer or null - */ - function arraybuffer( n ) { - var buf; - var i; - - // Convert the number of bytes to an index in our pool table: - i = log2( n ); - - // If we already have an available array buffer, use it... - if ( i < pool.length && pool[ i ].length ) { - return pool[ i ].pop(); - } - // Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate... - if ( nbytes+n > opts.highWaterMark ) { - return null; - } - buf = new ArrayBuffer( n ); - - // Update the running counter of allocated bytes: - nbytes += n; - - return buf; - } - - /** - * Returns a typed array. - * - * @private - * @param {Function} ctor - typed array constructor - * @param {NonNegativeInteger} len - view length - * @param {string} dtype - data type - * @returns {(TypedArray|null)} typed array or null - */ - function typedarray( ctor, len, dtype ) { - var buf; - if ( len === 0 ) { - return new ctor( 0 ); - } - buf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] ); - if ( buf === null ) { - return buf; - } - return new ctor( buf, 0, len ); - } - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length or an array-like object - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function malloc() { - var nargs; - var dtype; - var ctor; - var arr; - var out; - var set; - var get; - var len; - var i; - - nargs = arguments.length; - if ( nargs && isString( arguments[ nargs-1 ] ) ) { - nargs -= 1; - dtype = arguments[ nargs ]; - } else { - dtype = 'float64'; - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( '00d2k', dtype ) ); - } - if ( nargs <= 0 ) { - return new ctor( 0 ); - } - // Check if provided a typed array length... - if ( isNonNegativeInteger( arguments[ 0 ] ) ) { - return typedarray( ctor, arguments[ 0 ], dtype ); - } - // Check if provided an array-like object containing data elements... - if ( isCollection( arguments[ 0 ] ) ) { - arr = arguments[ 0 ]; - len = arr.length; - if ( isComplex128Array( arr ) ) { - arr = reinterpret128( arr, 0 ); - } else if ( isComplex64Array( arr ) ) { - arr = reinterpret64( arr, 0 ); - } else if ( /^complex/.test( dtype ) ) { - // Assume we've been provided an array of interleaved real and imaginary components... - len /= 2; - } - out = typedarray( ctor, len, dtype ); - if ( out === null ) { - return out; - } - if ( isCmplx128Array( out ) || isCmplx64Array( out ) ) { - out.set( arr ); - return out; - } - // Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other "unsafe" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring user's don't do ill-advised things... - get = arraylike2object( arr ).getter; - set = arraylike2object( out ).setter; - for ( i = 0; i < len; i++ ) { - set( out, i, get( arr, i ) ); - } - return out; - } - throw new TypeError( format( '00d33', arguments[ 0 ] ) ); - } - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {NonNegativeInteger} [len=0] - array length - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function calloc() { - var nargs; - var out; - var tmp; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - out = malloc(); - } else if ( nargs === 1 ) { - out = malloc( arguments[ 0 ] ); - } else { - out = malloc( arguments[ 0 ], arguments[ 1 ] ); - } - if ( out !== null ) { - // Initialize the memory... - if ( isCmplx128Array( out ) ) { - tmp = reinterpret128( out, 0 ); - } else if ( isCmplx64Array( out ) ) { - tmp = reinterpret64( out, 0 ); - } else { - tmp = out; - } - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = 0.0; - } - } - return out; - } - - /** - * Frees a typed array or typed array buffer. - * - * ## Notes - * - * - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., "freeing" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool. - * - * @private - * @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free - * @throws {TypeError} must provide a typed array or typed array buffer - * @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed - */ - function free( buf ) { - var n; - var p; - var i; - if ( isTypedArrayLike( buf ) && buf.buffer ) { - buf = buf.buffer; - } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) ); - } - if ( buf.byteLength > 0 ) { - n = floor( log2( buf.byteLength ) ); - - // Prohibit "freeing" array buffers which would potentially allow users to circumvent high water mark limits: - n = min( pool.length-1, n ); - - // Ensure that we do not attempt to free the same buffer more than once... - p = pool[ n ]; - for ( i = 0; i < p.length; i++ ) { - if ( p[ i ] === buf ) { - return false; - } - } - // Add the buffer to our pool of free buffers: - p.push( buf ); - } - return true; - } - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @private - */ - function clear() { - var i; - for ( i = 0; i < pool.length; i++ ) { - pool[ i ].length = 0; - } - nbytes = 0; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6c12a4e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Typed array pool. -* -* @module @stdlib/array-pool -* -* @example -* var typedarraypool = require( '@stdlib/array-pool' ); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8f69ee3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,63 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @name typedarraypool -* @type {Function} -* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a valid array length or an array-like object -* @throws {TypeError} must provide a recognized data type -* @returns {(TypedArray|null)} typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -var typedarraypool = factory(); - - -// EXPORTS // - -module.exports = typedarraypool; diff --git a/lib/pool.js b/lib/pool.js deleted file mode 100644 index 5abd287..0000000 --- a/lib/pool.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Initializes a cache for pooled typed array buffers. -* -* @private -* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size -* @returns {ArrayArray} initialized cache -*/ -function pool( n ) { - var out; - var i; - - out = []; - for ( i = 0; i < n+1; i++ ) { - out.push( [] ); - } - return out; -} - - -// EXPORTS // - -module.exports = pool; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 4135ec9..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'highWaterMark': 1024 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '00d2h', options ) ); - } - if ( hasOwnProp( options, 'highWaterMark' ) ) { - opts.highWaterMark = options.highWaterMark; - if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( '00d35', 'highWaterMark', opts.highWaterMark ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 558fca7..42614cf 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Typed array pool.", "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,76 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.0.x", - "@stdlib/array-buffer": "^0.0.x", - "@stdlib/array-typed-ctors": "^0.0.x", - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-arraybuffer": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-complex128array": "^0.0.x", - "@stdlib/assert-is-complex64array": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/assert-is-typed-array-like": "^0.0.x", - "@stdlib/math-base-special-ceil": "^0.0.x", - "@stdlib/math-base-special-ceil2": "^0.0.x", - "@stdlib/math-base-special-floor": "^0.0.x", - "@stdlib/math-base-special-log2": "^0.0.x", - "@stdlib/math-base-special-min": "^0.0.x", - "@stdlib/strided-base-reinterpret-complex128": "^0.0.x", - "@stdlib/strided-base-reinterpret-complex64": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-copy": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.0.x", - "@stdlib/array-complex64": "^0.0.x", - "@stdlib/array-float32": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/array-int16": "^0.0.x", - "@stdlib/array-int32": "^0.0.x", - "@stdlib/array-int8": "^0.0.x", - "@stdlib/array-uint16": "^0.0.x", - "@stdlib/array-uint32": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/array-uint8c": "^0.0.x", - "@stdlib/assert-instance-of": "^0.0.x", - "@stdlib/assert-is-complex-typed-array": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-typed-array": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/complex-float32": "^0.0.x", - "@stdlib/complex-float64": "^0.0.x", - "@stdlib/complex-imag": "^0.0.x", - "@stdlib/complex-imagf": "^0.0.x", - "@stdlib/complex-real": "^0.0.x", - "@stdlib/complex-realf": "^0.0.x", - "@stdlib/math-base-special-pow": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..bbe6a33 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 396aee2..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,2240 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function (no options)', function test( t ) { - t.strictEqual( typeof factory(), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - t.strictEqual( typeof factory( {} ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided a `highWaterMark` option which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (length)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a function which returns a typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, length)', function test( t ) { - var typedarraypool = factory(); - var arr; - - arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a `malloc` method which is a circular reference', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - var buf; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the returned function is a property which returns the pool\'s high water mark', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function supports specifying a high water mark which limits the total amount of memory a pool can allocate', function test( t ) { - var typedarraypool; - var arr1; - var arr2; - - typedarraypool = factory({ - 'highWaterMark': 64 // bytes - }); - - typedarraypool.clear(); - - arr1 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr1.length, 8, 'returns expected value' ); - t.strictEqual( arr1.byteLength, 64, 'returns expected value' ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - typedarraypool.free( arr1 ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Create an array which is less than or equal to the high water mark: - arr2 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr2.length, 8, 'returns expected value' ); - t.strictEqual( arr2.byteLength, 64, 'returns expected value' ); - - typedarraypool.free( arr2 ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a property which returns the total number of accumulated bytes', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var typedarraypool; - var arrs; - var i; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 54aa5ee..0000000 --- a/test/test.js +++ /dev/null @@ -1,1797 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var typedarraypool = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -}); From aca45894b02599f0b297172ef9dd411e82b5000a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 03:49:37 +0000 Subject: [PATCH 014/103] Transform error messages --- lib/factory.js | 6 +++--- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 2401100..b75e403 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -33,7 +33,7 @@ var ctors = require( '@stdlib/array-typed-ctors' ); var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( '@stdlib/utils-copy' ); var ArrayBuffer = require( '@stdlib/array-buffer' ); var ceil = require( '@stdlib/math-base-special-ceil' ); @@ -226,7 +226,7 @@ function factory( options ) { } ctor = ctors( dtype ); if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '00d2k', dtype ) ); } if ( nargs <= 0 ) { return new ctor( 0 ); @@ -263,7 +263,7 @@ function factory( options ) { } return out; } - throw new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) ); + throw new TypeError( format( '00d33', arguments[ 0 ] ) ); } /** diff --git a/lib/validate.js b/lib/validate.js index ce54890..4135ec9 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '00d2h', options ) ); } if ( hasOwnProp( options, 'highWaterMark' ) ) { opts.highWaterMark = options.highWaterMark; if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) ); + return new TypeError( format( '00d35', 'highWaterMark', opts.highWaterMark ) ); } } return null; diff --git a/package.json b/package.json index 50986ed..558fca7 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "@stdlib/math-base-special-min": "^0.0.x", "@stdlib/strided-base-reinterpret-complex128": "^0.0.x", "@stdlib/strided-base-reinterpret-complex64": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-copy": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", From fcd5c9e8769390b824282b771a050de1f5b50ccd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 17:24:09 +0000 Subject: [PATCH 015/103] Remove files --- index.d.ts | 359 ------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 3053 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 4500b91..0000000 --- a/index.d.ts +++ /dev/null @@ -1,359 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; -import ArrayBuffer = require( '@stdlib/array-buffer' ); - -/** -* Typed array or null. -*/ -type TypedArrayOrNull = RealOrComplexTypedArray | null; - -/** -* Interface defining pool options. -*/ -interface Options { - /** - * Maximum total memory which can be allocated. - */ - highWaterMark?: number; -} - -/** -* Pool interface. -*/ -interface Pool { - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr = typedarraypool(); - * // returns [] - * - * @example - * var arr = typedarraypool( 'float32' ); - * // returns [] - */ - ( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * // Allocate an array of doubles: - * var arr = typedarraypool( 5, 'float64' ); - * // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * typedarraypool.free( arr ); - * - * @example - * var arr1 = typedarraypool( [ 0.5, 0.5, 0.5 ] ); - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * @example - * var arr1 = [ 0.5, 0.5, 0.5 ]; - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - */ - ( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc(); - * // returns [] - * - * var arr2 = typedarraypool.calloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param length - typed array length - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc( 5 ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * var arr2 = typedarraypool.calloc( 5, 'uint8' ); - * // returns [ 0, 0, 0, 0, 0 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( length: number, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc(); - * // returns [] - * - * var arr2 = typedarraypool.malloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc( 5 ); - * // returns - * - * var arr2 = typedarraypool.malloc( 5, 'uint8' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 5.0, -3.0, 2.0 ] ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr2 = typedarraypool.malloc( arr1 ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr3 = typedarraypool.malloc( arr1, 'int32' ); - * // returns [ 5, -3, 2 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * typedarraypool.free( arr3 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ] ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * var arr2 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ], 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Frees a typed array or typed array buffer for use in a future allocation. - * - * @param buf - typed array or typed array buffer to free - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array for use in a future allocation: - * typedarraypool.free( arr ); - * - * // Create another typed array: - * arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array buffer for use in a future allocation: - * typedarraypool.free( arr.buffer ); - */ - free( buf: RealOrComplexTypedArray | ArrayBuffer ): void; - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr ); - * - * // ... - * - * // Clear all freed buffers: - * typedarraypool.clear(); - */ - clear(): void; - - /** - * Read-only property returning the pool's high water mark. - * - * ## Notes - * - * - Once a high water mark is reached, typed array allocation fails. - * - * @example - * var limit = typedarraypool.highWaterMark; - * // returns - */ - readonly highWaterMark: number; - - /** - * Read-only property returning the total number of allocated bytes. - * - * @example - * var arr = typedarraypool( 5, 'float64' ); - * - * var nbytes = typedarraypool.nbytes; - * // returns - */ - readonly nbytes: number; - - /** - * Creates a typed array pool. - * - * @param options - pool options - * @param options.highWaterMark - maximum total memory which can be allocated - * @throws must provide valid options - * @returns allocator - * - * @example - * var allocator = typedarraypool.factory(); - * - * // Allocate an array of doubles: - * var arr = allocator( 5, 'float64' ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * allocator.free( arr ); - */ - factory( options?: Options ): Pool; -} - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @param arg - an array length or an array-like object -* @param dtype - data type (default: 'float64') -* @returns typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -declare var typedarraypool: Pool; - - -// EXPORTS // - -export = typedarraypool; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 55d247f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";var w={highWaterMark:9007199254740992};function M(e,t){return y(t)?k(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(f("00d35","highWaterMark",e.highWaterMark)):null:new TypeError(f("00d2h",t))}function W(e){var t,r;for(t=[],r=0;rL.highWaterMark?null:(t=new c(e),k+=e,t)}function z(e,t,r){var s;return 0===t?new e(0):null===(s=q(b(t)*E[r]))?s:new e(s,0,t)}function C(){var e,i,n,l,j,c,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(n=d(i)))throw new TypeError(f("00d2k",i));if(e<=0)return new n(0);if(r(arguments[0]))return z(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,m(l)?l=h(l,0):o(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=z(n,u,i)))return j;if(B(j)||A(j))return j.set(l),j;for(g=p(l).getter,c=p(j).setter,b=0;b0){for(t=u(v(e.byteLength)),t=x(T.length-1,t),r=T[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = copy( defaults );\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '00d2k', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring user's don't do ill-advised things...\n\t\t\tget = arraylike2object( arr ).getter;\n\t\t\tset = arraylike2object( out ).setter;\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '00d33', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool' ;\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","copy","defaults","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","arraylike2object","getter","setter","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;4pEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,QAAS,gBAAiBP,EAAKI,gBAGxD,KARC,IAAIE,UAAWC,EAAQ,QAASN,ICtBzC,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,kHCcJG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,EAUzB,SAASK,EAAiBD,GACzB,OAASA,aAAeF,EA8BzB,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EAAOsB,EAAMC,GACRC,UAAUC,SACdJ,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOkB,EAAYC,EAAMC,EAAM5B,EAAKI,iBACpCgB,EAAS,EAETS,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB9B,EAAKI,eAC3C8B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOf,EAUR,SAASgB,EAAa3B,GACrB,IAAI4B,EACA1B,EAMJ,OAHAA,EAAIiB,EAAMnB,IAGDD,EAAKiB,QAAUjB,EAAMG,GAAIc,OAC1BjB,EAAMG,GAAI2B,MAGblB,EAAOX,EAAIT,EAAKI,cACb,MAERiC,EAAM,IAAIE,EAAa9B,GAGvBW,GAAUX,EAEH4B,GAYR,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,GAmB1B,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAxB,EACAP,EACAqC,EACAC,EACAN,EACA/B,EAUJ,GALCgC,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAO3B,EAAO6B,IAEb,MAAM,IAAIrC,UAAWC,EAAQ,QAASoC,IAEvC,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKpC,EAAsBmB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAzB,EAAMO,UAAW,IACPC,OACL0B,EAAmBlC,GACvBA,EAAMmC,EAAgBnC,EAAK,GAChBoC,EAAkBpC,GAC7BA,EAAMqC,EAAerC,EAAK,GACf,WAAWsC,KAAMZ,KAE5BD,GAAO,GAGK,QADbhC,EAAM8B,EAAYC,EAAMC,EAAKC,IAE5B,OAAOjC,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAIqC,IAAK9B,GACFP,EAKR,IAFAsC,EAAMQ,EAAkBvC,GAAMwC,OAC9BV,EAAMS,EAAkB9C,GAAMgD,OACxB/C,EAAI,EAAGA,EAAI+B,EAAK/B,IACrBoC,EAAKrC,EAAKC,EAAGqC,EAAK/B,EAAKN,IAExB,OAAOD,EAER,MAAM,IAAIJ,UAAWC,EAAQ,QAASiB,UAAW,KAiBlD,SAASO,IACR,IAAIe,EACApC,EACAiD,EACAhD,EAUJ,GAAa,QANZD,EADc,KADfoC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCmC,EADIzC,EAAiBR,GACf0C,EAAgB1C,EAAK,GAChBM,EAAgBN,GACrB4C,EAAe5C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAIgD,EAAIlC,OAAQd,IAC5BgD,EAAKhD,GAAM,EAGb,OAAOD,EAeR,SAASsB,EAAMK,GACd,IAAI5B,EACAmD,EACAjD,EACJ,GAAKkD,EAAkBxB,IAASA,EAAIyB,OACnCzB,EAAMA,EAAIyB,YACJ,IAAMC,EAAe1B,GAC3B,MAAM,IAAI/B,UAAWC,EAAQ,4EAA6E8B,IAE3G,GAAKA,EAAI2B,WAAa,EAAI,CAQzB,IAPAvD,EAAIwD,EAAOrC,EAAMS,EAAI2B,aAGrBvD,EAAIyD,EAAK1D,EAAKiB,OAAO,EAAGhB,GAGxBmD,EAAIpD,EAAMC,GACJE,EAAI,EAAGA,EAAIiD,EAAEnC,OAAQd,IAC1B,GAAKiD,EAAGjD,KAAQ0B,EACf,OAAO,EAITuB,EAAEhD,KAAMyB,GAET,OAAO,EAQR,SAASJ,IACR,IAAItB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKiB,OAAQd,IAC7BH,EAAMG,GAAIc,OAAS,EAEpBL,EAAS,GCjTR,IAAC+C,EAAiBhD,ICPrBU,EAAAuC,EAAA,UAAAjD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index bbe6a33..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From fec7358f6839053f597703862b58d95d2041f27d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 17:25:08 +0000 Subject: [PATCH 016/103] 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 | 43 +- benchmark/benchmark.calloc.js | 246 -- benchmark/benchmark.factory.js | 71 - benchmark/benchmark.js | 246 -- benchmark/benchmark.length.complex128.js | 102 - benchmark/benchmark.length.complex64.js | 102 - benchmark/benchmark.length.float32.js | 102 - benchmark/benchmark.length.float64.js | 102 - benchmark/benchmark.length.int16.js | 102 - benchmark/benchmark.length.int32.js | 102 - benchmark/benchmark.length.int8.js | 102 - benchmark/benchmark.length.uint16.js | 102 - benchmark/benchmark.length.uint32.js | 102 - benchmark/benchmark.length.uint8.js | 102 - benchmark/benchmark.length.uint8c.js | 102 - benchmark/benchmark.malloc.js | 246 -- branches.md | 53 - docs/repl.txt | 347 --- docs/types/test.ts | 193 -- examples/index.js | 80 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/bytes_per_element.json | 13 - lib/defaults.json | 3 - lib/factory.js | 370 --- lib/index.js | 56 - lib/main.js | 63 - lib/pool.js | 44 - lib/validate.js | 66 - package.json | 97 +- stats.html | 2689 +++++++++++++++++++++ test/test.factory.js | 2240 ----------------- test/test.js | 1797 -------------- 57 files changed, 2718 insertions(+), 10278 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.calloc.js delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.complex128.js delete mode 100644 benchmark/benchmark.length.complex64.js delete mode 100644 benchmark/benchmark.length.float32.js delete mode 100644 benchmark/benchmark.length.float64.js delete mode 100644 benchmark/benchmark.length.int16.js delete mode 100644 benchmark/benchmark.length.int32.js delete mode 100644 benchmark/benchmark.length.int8.js delete mode 100644 benchmark/benchmark.length.uint16.js delete mode 100644 benchmark/benchmark.length.uint32.js delete mode 100644 benchmark/benchmark.length.uint8.js delete mode 100644 benchmark/benchmark.length.uint8c.js delete mode 100644 benchmark/benchmark.malloc.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/bytes_per_element.json delete mode 100644 lib/defaults.json delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/pool.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index c99a61a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-09-01T01:45:31.214Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ea35f20..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/array/pool) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 fc6d38a..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/array/pool) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -482,7 +481,7 @@ console.log( 'nbytes: %d', typedarray.nbytes ); ## 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]. @@ -548,7 +547,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm diff --git a/benchmark/benchmark.calloc.js b/benchmark/benchmark.calloc.js deleted file mode 100644 index e5a1c77..0000000 --- a/benchmark/benchmark.calloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':calloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index f7cd676..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = typedarray.factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:highWaterMark', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'highWaterMark': 0 - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.highWaterMark = i; - f = typedarray.factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a023d2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.complex128.js b/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 47b623b..0000000 --- a/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex64.js b/benchmark/benchmark.length.complex64.js deleted file mode 100644 index 40a412b..0000000 --- a/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float32.js b/benchmark/benchmark.length.float32.js deleted file mode 100644 index 0227ed7..0000000 --- a/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float64.js b/benchmark/benchmark.length.float64.js deleted file mode 100644 index 2dbac1c..0000000 --- a/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int16.js b/benchmark/benchmark.length.int16.js deleted file mode 100644 index e2a8adc..0000000 --- a/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int32.js b/benchmark/benchmark.length.int32.js deleted file mode 100644 index e4df0aa..0000000 --- a/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int8.js b/benchmark/benchmark.length.int8.js deleted file mode 100644 index 7ceac11..0000000 --- a/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint16.js b/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 9a532b6..0000000 --- a/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint32.js b/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 98f2d7f..0000000 --- a/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8.js b/benchmark/benchmark.length.uint8.js deleted file mode 100644 index 8359249..0000000 --- a/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8c.js b/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index d47d023..0000000 --- a/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.malloc.js b/benchmark/benchmark.malloc.js deleted file mode 100644 index d4eea72..0000000 --- a/benchmark/benchmark.malloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':malloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 8fce14f..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/array/pool" -click B href "https://github.com/stdlib-js/array-pool/tree/main" -click C href "https://github.com/stdlib-js/array-pool/tree/production" -click D href "https://github.com/stdlib-js/array-pool/tree/esm" -click E href "https://github.com/stdlib-js/array-pool/tree/deno" -click F href "https://github.com/stdlib-js/array-pool/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/pool -[production-url]: https://github.com/stdlib-js/array-pool/tree/production -[deno-url]: https://github.com/stdlib-js/array-pool/tree/deno -[umd-url]: https://github.com/stdlib-js/array-pool/tree/umd -[esm-url]: https://github.com/stdlib-js/array-pool/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5244595..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,347 +0,0 @@ - -{{alias}}( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - Memory is **uninitialized**, which means that the contents of a returned - typed array may contain sensitive contents. - - The function supports the following data types: - - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - The default typed array data type is `float64`. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}() - [] - > arr = {{alias}}( 'float32' ) - [] - - -{{alias}}( length[, dtype] ) - Returns an uninitialized typed array having a specified length from a typed - array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > arr = {{alias}}( 5, 'int32' ) - - - -{{alias}}( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - This method shares the same security vulnerabilities mentioned above. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc() - - > arr = {{alias}}.malloc( 'float32' ) - - - -{{alias}}.malloc( length[, dtype] ) - Returns a typed array having a specified length from a typed array memory - pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc( 5 ) - - > arr = {{alias}}.malloc( 5, 'int32' ) - - - -{{alias}}.malloc( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}.malloc( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.calloc( [dtype] ) - Returns a zero-initialized typed array from a typed array memory pool. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc() - [] - > arr = {{alias}}.calloc( 'float32' ) - [] - - -{{alias}}.calloc( length[, dtype] ) - Returns a zero-initialized typed array having a specified length from a - typed array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}.calloc( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}.free( buf ) - Frees a typed array or typed array buffer for use in a future allocation. - - Parameters - ---------- - buf: TypedArray|ArrayBuffer - Typed array or typed array buffer to free. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ) - - -{{alias}}.clear() - Clears the typed array pool allowing garbage collection of previously - allocated (and currently free) array buffers. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - > {{alias}}.clear() - - -{{alias}}.highWaterMark - Read-only property returning the pool's high water mark. - - Once a high water mark is reached, typed array allocation fails. - - Examples - -------- - > {{alias}}.highWaterMark - - -{{alias}}.nbytes - Read-only property returning the total number of allocated bytes. - - The returned value is the total accumulated value. Hence, anytime a pool - must allocate a new array buffer (i.e., more memory), the pool increments - this value. - - The only time this value is decremented is when a pool is cleared. - - This behavior means that, while allocated buffers which are never freed may, - in fact, be garbage collected, they continue to count against the high water - mark limit. - - Accordingly, you should *always* free allocated buffers in order to prevent - the pool from believing that non-freed buffers are continually in use. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.nbytes - - -{{alias}}.factory( [options] ) - Creates a typed array pool. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.highWaterMark: integer (optional) - Maximum total memory (in bytes) which can be allocated. - - Returns - ------- - fcn: Function - Function for creating typed arrays from a typed array memory pool. - - Examples - -------- - > var pool = {{alias}}.factory(); - > var arr1 = pool( 3, 'float64' ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1014bba..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,193 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-empty */ -/* tslint:disable:no-unused-expression */ - -import typedarraypool = require( './index' ); - - -// TESTS // - -// The function returns a typed array or null... -{ - typedarraypool(); // $ExpectType TypedArrayOrNull - typedarraypool( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the function is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool( true ); // $ExpectError - typedarraypool( false ); // $ExpectError - typedarraypool( null ); // $ExpectError - typedarraypool( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized data type... -{ - typedarraypool( 4, true ); // $ExpectError - typedarraypool( 4, false ); // $ExpectError - typedarraypool( 4, null ); // $ExpectError - typedarraypool( 4, 'abc' ); // $ExpectError - typedarraypool( 4, 123 ); // $ExpectError - typedarraypool( 4, [] ); // $ExpectError - typedarraypool( 4, {} ); // $ExpectError - typedarraypool( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an incorrect number of arguments... -{ - typedarraypool( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `malloc` method which returns a typed array or null... -{ - typedarraypool.malloc(); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.malloc( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `malloc` method is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool.malloc( true ); // $ExpectError - typedarraypool.malloc( false ); // $ExpectError - typedarraypool.malloc( null ); // $ExpectError - typedarraypool.malloc( {} ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.malloc( 4, true ); // $ExpectError - typedarraypool.malloc( 4, false ); // $ExpectError - typedarraypool.malloc( 4, null ); // $ExpectError - typedarraypool.malloc( 4, 'abc' ); // $ExpectError - typedarraypool.malloc( 4, 123 ); // $ExpectError - typedarraypool.malloc( 4, [] ); // $ExpectError - typedarraypool.malloc( 4, {} ); // $ExpectError - typedarraypool.malloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided an incorrect number of arguments... -{ - typedarraypool.malloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `calloc` method which returns a typed array or null... -{ - typedarraypool.calloc(); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `calloc` method is provided a first argument which is not a number... -{ - typedarraypool.calloc( 'abc' ); // $ExpectError - typedarraypool.calloc( true ); // $ExpectError - typedarraypool.calloc( false ); // $ExpectError - typedarraypool.calloc( null ); // $ExpectError - typedarraypool.calloc( {} ); // $ExpectError - typedarraypool.calloc( [] ); // $ExpectError - typedarraypool.calloc( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.calloc( 4, true ); // $ExpectError - typedarraypool.calloc( 4, false ); // $ExpectError - typedarraypool.calloc( 4, null ); // $ExpectError - typedarraypool.calloc( 4, 'abc' ); // $ExpectError - typedarraypool.calloc( 4, 123 ); // $ExpectError - typedarraypool.calloc( 4, [] ); // $ExpectError - typedarraypool.calloc( 4, {} ); // $ExpectError - typedarraypool.calloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided an incorrect number of arguments... -{ - typedarraypool.calloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `factory` method which returns a typed array pool.. -{ - typedarraypool.factory(); // $ExpectType Pool - typedarraypool.factory( { 'highWaterMark': 556 } ); // $ExpectType Pool -} - -// The compiler throws an error if the `factory` method is provided a `highWaterMark` option which is not a number... -{ - typedarraypool.factory( { 'highWaterMark': true } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': false } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': 'abc' } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': null } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': [] } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': {} } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an incorrect number of arguments... -{ - typedarraypool.factory( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` method which returns void... -{ - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.free( arr ); // $ExpectType void -} - -// The compiler throws an error if the `free` method is provided a first argument which is neither a typed array nor array buffer... -{ - typedarraypool.free( true ); // $ExpectError - typedarraypool.free( false ); // $ExpectError - typedarraypool.free( 123 ); // $ExpectError - typedarraypool.free( 'abc' ); // $ExpectError - typedarraypool.free( null ); // $ExpectError - typedarraypool.free( {} ); // $ExpectError - typedarraypool.free( ( x: number ): number => x ); // $ExpectError -} - -// Attached to the main export is a `clear` method which returns void... -{ - typedarraypool.clear(); // $ExpectType void -} - -// The compiler throws an error if the `clear` method is provided arguments... -{ - typedarraypool.clear( {} ); // $ExpectError - typedarraypool.clear( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `highWaterMark` property... -{ - typedarraypool.highWaterMark; // $ExpectType number -} - -// Attached to the main export is a `nbytes` property... -{ - typedarraypool.nbytes; // $ExpectType number -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 24a7846..0000000 --- a/examples/index.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 randu = require( '@stdlib/random-base-randu' ); -var typedarraypool = require( './../lib' ); - -// Create a typed array pool which can allocate at most 1GB: -var typedarray = typedarraypool.factory({ - 'highWaterMark': 1e9 -}); - -// Inspect the pool: -console.log( 'Max bytes: %d', typedarray.highWaterMark ); -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Allocate an array for storing double-precision floating-point numbers: -var arr1 = typedarray( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Fill the array... -var i; -for ( i = 0; i < arr1.length; i++ ) { - arr1[ i ] = randu(); -} - -// Inspect array contents: -console.log( arr1 ); - -// Free the array: -typedarray.free( arr1 ); - -// Allocate another array similar to the previous one: -var arr2 = typedarray( 5, 'float64' ); -// returns - -// Check that we have been returned a new typed array view: -console.log( arr2 === arr1 ); -// => false - -// Inspect array contents: -console.log( arr2 ); - -// Free the array: -typedarray.free( arr2 ); - -// Allocate an initialized array: -var arr3 = typedarray.calloc( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect array contents: -console.log( arr3 ); - -// Free the array: -typedarray.free( arr3 ); - -// Clear the pool: -typedarray.clear(); - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 239fcdc..4500b91 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; import ArrayBuffer = require( '@stdlib/array-buffer' ); diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..55d247f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";var w={highWaterMark:9007199254740992};function M(e,t){return y(t)?k(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(f("00d35","highWaterMark",e.highWaterMark)):null:new TypeError(f("00d2h",t))}function W(e){var t,r;for(t=[],r=0;rL.highWaterMark?null:(t=new c(e),k+=e,t)}function z(e,t,r){var s;return 0===t?new e(0):null===(s=q(b(t)*E[r]))?s:new e(s,0,t)}function C(){var e,i,n,l,j,c,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(n=d(i)))throw new TypeError(f("00d2k",i));if(e<=0)return new n(0);if(r(arguments[0]))return z(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,m(l)?l=h(l,0):o(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=z(n,u,i)))return j;if(B(j)||A(j))return j.set(l),j;for(g=p(l).getter,c=p(j).setter,b=0;b0){for(t=u(v(e.byteLength)),t=x(T.length-1,t),r=T[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = copy( defaults );\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '00d2k', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring user's don't do ill-advised things...\n\t\t\tget = arraylike2object( arr ).getter;\n\t\t\tset = arraylike2object( out ).setter;\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '00d33', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool' ;\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","copy","defaults","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","arraylike2object","getter","setter","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;4pEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,QAAS,gBAAiBP,EAAKI,gBAGxD,KARC,IAAIE,UAAWC,EAAQ,QAASN,ICtBzC,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,kHCcJG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,EAUzB,SAASK,EAAiBD,GACzB,OAASA,aAAeF,EA8BzB,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EAAOsB,EAAMC,GACRC,UAAUC,SACdJ,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOkB,EAAYC,EAAMC,EAAM5B,EAAKI,iBACpCgB,EAAS,EAETS,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB9B,EAAKI,eAC3C8B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOf,EAUR,SAASgB,EAAa3B,GACrB,IAAI4B,EACA1B,EAMJ,OAHAA,EAAIiB,EAAMnB,IAGDD,EAAKiB,QAAUjB,EAAMG,GAAIc,OAC1BjB,EAAMG,GAAI2B,MAGblB,EAAOX,EAAIT,EAAKI,cACb,MAERiC,EAAM,IAAIE,EAAa9B,GAGvBW,GAAUX,EAEH4B,GAYR,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,GAmB1B,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAxB,EACAP,EACAqC,EACAC,EACAN,EACA/B,EAUJ,GALCgC,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAO3B,EAAO6B,IAEb,MAAM,IAAIrC,UAAWC,EAAQ,QAASoC,IAEvC,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKpC,EAAsBmB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAzB,EAAMO,UAAW,IACPC,OACL0B,EAAmBlC,GACvBA,EAAMmC,EAAgBnC,EAAK,GAChBoC,EAAkBpC,GAC7BA,EAAMqC,EAAerC,EAAK,GACf,WAAWsC,KAAMZ,KAE5BD,GAAO,GAGK,QADbhC,EAAM8B,EAAYC,EAAMC,EAAKC,IAE5B,OAAOjC,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAIqC,IAAK9B,GACFP,EAKR,IAFAsC,EAAMQ,EAAkBvC,GAAMwC,OAC9BV,EAAMS,EAAkB9C,GAAMgD,OACxB/C,EAAI,EAAGA,EAAI+B,EAAK/B,IACrBoC,EAAKrC,EAAKC,EAAGqC,EAAK/B,EAAKN,IAExB,OAAOD,EAER,MAAM,IAAIJ,UAAWC,EAAQ,QAASiB,UAAW,KAiBlD,SAASO,IACR,IAAIe,EACApC,EACAiD,EACAhD,EAUJ,GAAa,QANZD,EADc,KADfoC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCmC,EADIzC,EAAiBR,GACf0C,EAAgB1C,EAAK,GAChBM,EAAgBN,GACrB4C,EAAe5C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAIgD,EAAIlC,OAAQd,IAC5BgD,EAAKhD,GAAM,EAGb,OAAOD,EAeR,SAASsB,EAAMK,GACd,IAAI5B,EACAmD,EACAjD,EACJ,GAAKkD,EAAkBxB,IAASA,EAAIyB,OACnCzB,EAAMA,EAAIyB,YACJ,IAAMC,EAAe1B,GAC3B,MAAM,IAAI/B,UAAWC,EAAQ,4EAA6E8B,IAE3G,GAAKA,EAAI2B,WAAa,EAAI,CAQzB,IAPAvD,EAAIwD,EAAOrC,EAAMS,EAAI2B,aAGrBvD,EAAIyD,EAAK1D,EAAKiB,OAAO,EAAGhB,GAGxBmD,EAAIpD,EAAMC,GACJE,EAAI,EAAGA,EAAIiD,EAAEnC,OAAQd,IAC1B,GAAKiD,EAAGjD,KAAQ0B,EACf,OAAO,EAITuB,EAAEhD,KAAMyB,GAET,OAAO,EAQR,SAASJ,IACR,IAAItB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKiB,OAAQd,IAC7BH,EAAMG,GAAIc,OAAS,EAEpBL,EAAS,GCjTR,IAAC+C,EAAiBhD,ICPrBU,EAAAuC,EAAA,UAAAjD"} \ No newline at end of file diff --git a/lib/bytes_per_element.json b/lib/bytes_per_element.json deleted file mode 100644 index f97fe70..0000000 --- a/lib/bytes_per_element.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "float64": 8, - "float32": 4, - "int16": 2, - "int32": 4, - "int8": 1, - "uint16": 2, - "uint32": 4, - "uint8": 1, - "uint8c": 1, - "complex64": 8, - "complex128": 16 -} diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index c71c8f2..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "highWaterMark": 9007199254740992 -} diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index b75e403..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,370 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var isComplex64Array = require( '@stdlib/assert-is-complex64array' ); -var isComplex128Array = require( '@stdlib/assert-is-complex128array' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var ctors = require( '@stdlib/array-typed-ctors' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( '@stdlib/utils-copy' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil = require( '@stdlib/math-base-special-ceil' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); -var log2 = require( '@stdlib/math-base-special-log2' ); -var min = require( '@stdlib/math-base-special-min' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); -var createPool = require( './pool.js' ); -var BYTES_PER_ELEMENT = require( './bytes_per_element.json' ); - - -// VARIABLES // - -var Complex64Array = ctors( 'complex64' ); -var Complex128Array = ctors( 'complex128' ); - - -// FUNCTIONS // - -/** -* Tests whether an array is a single-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a single-precision complex floating-point number array -*/ -function isCmplx64Array( arr ) { - return ( arr instanceof Complex64Array ); -} - -/** -* Tests whether an array is a double-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a double-precision complex floating-point number array -*/ -function isCmplx128Array( arr ) { - return ( arr instanceof Complex128Array ); -} - - -// MAIN // - -/** -* Creates a typed array pool. -* -* @param {Options} [options] - pool options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} allocator -* -* @example -* var typedarraypool = factory(); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -function factory( options ) { - var nbytes; - var pool; - var opts; - var err; - - opts = copy( defaults ); - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - pool = createPool( ceil( log2( opts.highWaterMark ) ) ); - nbytes = 0; - - setReadOnly( malloc, 'malloc', malloc ); // circular reference - setReadOnly( malloc, 'calloc', calloc ); - setReadOnly( malloc, 'free', free ); - setReadOnly( malloc, 'clear', clear ); - setReadOnly( malloc, 'highWaterMark', opts.highWaterMark ); - setReadOnlyAccessor( malloc, 'nbytes', getBytes ); - - return malloc; - - /** - * Returns the number of allocated bytes. - * - * @private - * @returns {NonNegativeInteger} number of allocated bytes - */ - function getBytes() { - return nbytes; - } - - /** - * Returns an array buffer. - * - * @private - * @param {NonNegativeInteger} n - number of bytes - * @returns {(ArrayBuffer|null)} array buffer or null - */ - function arraybuffer( n ) { - var buf; - var i; - - // Convert the number of bytes to an index in our pool table: - i = log2( n ); - - // If we already have an available array buffer, use it... - if ( i < pool.length && pool[ i ].length ) { - return pool[ i ].pop(); - } - // Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate... - if ( nbytes+n > opts.highWaterMark ) { - return null; - } - buf = new ArrayBuffer( n ); - - // Update the running counter of allocated bytes: - nbytes += n; - - return buf; - } - - /** - * Returns a typed array. - * - * @private - * @param {Function} ctor - typed array constructor - * @param {NonNegativeInteger} len - view length - * @param {string} dtype - data type - * @returns {(TypedArray|null)} typed array or null - */ - function typedarray( ctor, len, dtype ) { - var buf; - if ( len === 0 ) { - return new ctor( 0 ); - } - buf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] ); - if ( buf === null ) { - return buf; - } - return new ctor( buf, 0, len ); - } - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length or an array-like object - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function malloc() { - var nargs; - var dtype; - var ctor; - var arr; - var out; - var set; - var get; - var len; - var i; - - nargs = arguments.length; - if ( nargs && isString( arguments[ nargs-1 ] ) ) { - nargs -= 1; - dtype = arguments[ nargs ]; - } else { - dtype = 'float64'; - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( '00d2k', dtype ) ); - } - if ( nargs <= 0 ) { - return new ctor( 0 ); - } - // Check if provided a typed array length... - if ( isNonNegativeInteger( arguments[ 0 ] ) ) { - return typedarray( ctor, arguments[ 0 ], dtype ); - } - // Check if provided an array-like object containing data elements... - if ( isCollection( arguments[ 0 ] ) ) { - arr = arguments[ 0 ]; - len = arr.length; - if ( isComplex128Array( arr ) ) { - arr = reinterpret128( arr, 0 ); - } else if ( isComplex64Array( arr ) ) { - arr = reinterpret64( arr, 0 ); - } else if ( /^complex/.test( dtype ) ) { - // Assume we've been provided an array of interleaved real and imaginary components... - len /= 2; - } - out = typedarray( ctor, len, dtype ); - if ( out === null ) { - return out; - } - if ( isCmplx128Array( out ) || isCmplx64Array( out ) ) { - out.set( arr ); - return out; - } - // Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other "unsafe" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring user's don't do ill-advised things... - get = arraylike2object( arr ).getter; - set = arraylike2object( out ).setter; - for ( i = 0; i < len; i++ ) { - set( out, i, get( arr, i ) ); - } - return out; - } - throw new TypeError( format( '00d33', arguments[ 0 ] ) ); - } - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {NonNegativeInteger} [len=0] - array length - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function calloc() { - var nargs; - var out; - var tmp; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - out = malloc(); - } else if ( nargs === 1 ) { - out = malloc( arguments[ 0 ] ); - } else { - out = malloc( arguments[ 0 ], arguments[ 1 ] ); - } - if ( out !== null ) { - // Initialize the memory... - if ( isCmplx128Array( out ) ) { - tmp = reinterpret128( out, 0 ); - } else if ( isCmplx64Array( out ) ) { - tmp = reinterpret64( out, 0 ); - } else { - tmp = out; - } - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = 0.0; - } - } - return out; - } - - /** - * Frees a typed array or typed array buffer. - * - * ## Notes - * - * - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., "freeing" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool. - * - * @private - * @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free - * @throws {TypeError} must provide a typed array or typed array buffer - * @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed - */ - function free( buf ) { - var n; - var p; - var i; - if ( isTypedArrayLike( buf ) && buf.buffer ) { - buf = buf.buffer; - } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) ); - } - if ( buf.byteLength > 0 ) { - n = floor( log2( buf.byteLength ) ); - - // Prohibit "freeing" array buffers which would potentially allow users to circumvent high water mark limits: - n = min( pool.length-1, n ); - - // Ensure that we do not attempt to free the same buffer more than once... - p = pool[ n ]; - for ( i = 0; i < p.length; i++ ) { - if ( p[ i ] === buf ) { - return false; - } - } - // Add the buffer to our pool of free buffers: - p.push( buf ); - } - return true; - } - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @private - */ - function clear() { - var i; - for ( i = 0; i < pool.length; i++ ) { - pool[ i ].length = 0; - } - nbytes = 0; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6c12a4e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Typed array pool. -* -* @module @stdlib/array-pool -* -* @example -* var typedarraypool = require( '@stdlib/array-pool' ); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8f69ee3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,63 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @name typedarraypool -* @type {Function} -* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a valid array length or an array-like object -* @throws {TypeError} must provide a recognized data type -* @returns {(TypedArray|null)} typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -var typedarraypool = factory(); - - -// EXPORTS // - -module.exports = typedarraypool; diff --git a/lib/pool.js b/lib/pool.js deleted file mode 100644 index 5abd287..0000000 --- a/lib/pool.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Initializes a cache for pooled typed array buffers. -* -* @private -* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size -* @returns {ArrayArray} initialized cache -*/ -function pool( n ) { - var out; - var i; - - out = []; - for ( i = 0; i < n+1; i++ ) { - out.push( [] ); - } - return out; -} - - -// EXPORTS // - -module.exports = pool; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 4135ec9..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'highWaterMark': 1024 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '00d2h', options ) ); - } - if ( hasOwnProp( options, 'highWaterMark' ) ) { - opts.highWaterMark = options.highWaterMark; - if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( '00d35', 'highWaterMark', opts.highWaterMark ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 558fca7..42614cf 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Typed array pool.", "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,76 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.0.x", - "@stdlib/array-buffer": "^0.0.x", - "@stdlib/array-typed-ctors": "^0.0.x", - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-arraybuffer": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-complex128array": "^0.0.x", - "@stdlib/assert-is-complex64array": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/assert-is-typed-array-like": "^0.0.x", - "@stdlib/math-base-special-ceil": "^0.0.x", - "@stdlib/math-base-special-ceil2": "^0.0.x", - "@stdlib/math-base-special-floor": "^0.0.x", - "@stdlib/math-base-special-log2": "^0.0.x", - "@stdlib/math-base-special-min": "^0.0.x", - "@stdlib/strided-base-reinterpret-complex128": "^0.0.x", - "@stdlib/strided-base-reinterpret-complex64": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-copy": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.0.x", - "@stdlib/array-complex64": "^0.0.x", - "@stdlib/array-float32": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/array-int16": "^0.0.x", - "@stdlib/array-int32": "^0.0.x", - "@stdlib/array-int8": "^0.0.x", - "@stdlib/array-uint16": "^0.0.x", - "@stdlib/array-uint32": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/array-uint8c": "^0.0.x", - "@stdlib/assert-instance-of": "^0.0.x", - "@stdlib/assert-is-complex-typed-array": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-typed-array": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/complex-float32": "^0.0.x", - "@stdlib/complex-float64": "^0.0.x", - "@stdlib/complex-imag": "^0.0.x", - "@stdlib/complex-imagf": "^0.0.x", - "@stdlib/complex-real": "^0.0.x", - "@stdlib/complex-realf": "^0.0.x", - "@stdlib/math-base-special-pow": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..efcf9f1 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 396aee2..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,2240 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function (no options)', function test( t ) { - t.strictEqual( typeof factory(), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - t.strictEqual( typeof factory( {} ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided a `highWaterMark` option which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (length)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a function which returns a typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, length)', function test( t ) { - var typedarraypool = factory(); - var arr; - - arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a `malloc` method which is a circular reference', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - var buf; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the returned function is a property which returns the pool\'s high water mark', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function supports specifying a high water mark which limits the total amount of memory a pool can allocate', function test( t ) { - var typedarraypool; - var arr1; - var arr2; - - typedarraypool = factory({ - 'highWaterMark': 64 // bytes - }); - - typedarraypool.clear(); - - arr1 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr1.length, 8, 'returns expected value' ); - t.strictEqual( arr1.byteLength, 64, 'returns expected value' ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - typedarraypool.free( arr1 ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Create an array which is less than or equal to the high water mark: - arr2 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr2.length, 8, 'returns expected value' ); - t.strictEqual( arr2.byteLength, 64, 'returns expected value' ); - - typedarraypool.free( arr2 ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a property which returns the total number of accumulated bytes', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var typedarraypool; - var arrs; - var i; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 54aa5ee..0000000 --- a/test/test.js +++ /dev/null @@ -1,1797 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var typedarraypool = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -}); From d9b15619c8ac0e3d007d17985a42035770526d0b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 02:13:58 +0000 Subject: [PATCH 017/103] Transform error messages --- lib/factory.js | 6 +++--- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 2401100..b75e403 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -33,7 +33,7 @@ var ctors = require( '@stdlib/array-typed-ctors' ); var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( '@stdlib/utils-copy' ); var ArrayBuffer = require( '@stdlib/array-buffer' ); var ceil = require( '@stdlib/math-base-special-ceil' ); @@ -226,7 +226,7 @@ function factory( options ) { } ctor = ctors( dtype ); if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '00d2k', dtype ) ); } if ( nargs <= 0 ) { return new ctor( 0 ); @@ -263,7 +263,7 @@ function factory( options ) { } return out; } - throw new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) ); + throw new TypeError( format( '00d33', arguments[ 0 ] ) ); } /** diff --git a/lib/validate.js b/lib/validate.js index ce54890..4135ec9 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '00d2h', options ) ); } if ( hasOwnProp( options, 'highWaterMark' ) ) { opts.highWaterMark = options.highWaterMark; if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) ); + return new TypeError( format( '00d35', 'highWaterMark', opts.highWaterMark ) ); } } return null; diff --git a/package.json b/package.json index 50986ed..558fca7 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "@stdlib/math-base-special-min": "^0.0.x", "@stdlib/strided-base-reinterpret-complex128": "^0.0.x", "@stdlib/strided-base-reinterpret-complex64": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-copy": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", From 32309cde7fc71d6415f4da64e2957d07f0be1345 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 15:55:19 +0000 Subject: [PATCH 018/103] Remove files --- index.d.ts | 359 ------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 3053 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 4500b91..0000000 --- a/index.d.ts +++ /dev/null @@ -1,359 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; -import ArrayBuffer = require( '@stdlib/array-buffer' ); - -/** -* Typed array or null. -*/ -type TypedArrayOrNull = RealOrComplexTypedArray | null; - -/** -* Interface defining pool options. -*/ -interface Options { - /** - * Maximum total memory which can be allocated. - */ - highWaterMark?: number; -} - -/** -* Pool interface. -*/ -interface Pool { - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr = typedarraypool(); - * // returns [] - * - * @example - * var arr = typedarraypool( 'float32' ); - * // returns [] - */ - ( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * // Allocate an array of doubles: - * var arr = typedarraypool( 5, 'float64' ); - * // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * typedarraypool.free( arr ); - * - * @example - * var arr1 = typedarraypool( [ 0.5, 0.5, 0.5 ] ); - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * @example - * var arr1 = [ 0.5, 0.5, 0.5 ]; - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - */ - ( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc(); - * // returns [] - * - * var arr2 = typedarraypool.calloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param length - typed array length - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc( 5 ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * var arr2 = typedarraypool.calloc( 5, 'uint8' ); - * // returns [ 0, 0, 0, 0, 0 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( length: number, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc(); - * // returns [] - * - * var arr2 = typedarraypool.malloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc( 5 ); - * // returns - * - * var arr2 = typedarraypool.malloc( 5, 'uint8' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 5.0, -3.0, 2.0 ] ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr2 = typedarraypool.malloc( arr1 ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr3 = typedarraypool.malloc( arr1, 'int32' ); - * // returns [ 5, -3, 2 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * typedarraypool.free( arr3 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ] ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * var arr2 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ], 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Frees a typed array or typed array buffer for use in a future allocation. - * - * @param buf - typed array or typed array buffer to free - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array for use in a future allocation: - * typedarraypool.free( arr ); - * - * // Create another typed array: - * arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array buffer for use in a future allocation: - * typedarraypool.free( arr.buffer ); - */ - free( buf: RealOrComplexTypedArray | ArrayBuffer ): void; - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr ); - * - * // ... - * - * // Clear all freed buffers: - * typedarraypool.clear(); - */ - clear(): void; - - /** - * Read-only property returning the pool's high water mark. - * - * ## Notes - * - * - Once a high water mark is reached, typed array allocation fails. - * - * @example - * var limit = typedarraypool.highWaterMark; - * // returns - */ - readonly highWaterMark: number; - - /** - * Read-only property returning the total number of allocated bytes. - * - * @example - * var arr = typedarraypool( 5, 'float64' ); - * - * var nbytes = typedarraypool.nbytes; - * // returns - */ - readonly nbytes: number; - - /** - * Creates a typed array pool. - * - * @param options - pool options - * @param options.highWaterMark - maximum total memory which can be allocated - * @throws must provide valid options - * @returns allocator - * - * @example - * var allocator = typedarraypool.factory(); - * - * // Allocate an array of doubles: - * var arr = allocator( 5, 'float64' ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * allocator.free( arr ); - */ - factory( options?: Options ): Pool; -} - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @param arg - an array length or an array-like object -* @param dtype - data type (default: 'float64') -* @returns typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -declare var typedarraypool: Pool; - - -// EXPORTS // - -export = typedarraypool; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 55d247f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";var w={highWaterMark:9007199254740992};function M(e,t){return y(t)?k(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(f("00d35","highWaterMark",e.highWaterMark)):null:new TypeError(f("00d2h",t))}function W(e){var t,r;for(t=[],r=0;rL.highWaterMark?null:(t=new c(e),k+=e,t)}function z(e,t,r){var s;return 0===t?new e(0):null===(s=q(b(t)*E[r]))?s:new e(s,0,t)}function C(){var e,i,n,l,j,c,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(n=d(i)))throw new TypeError(f("00d2k",i));if(e<=0)return new n(0);if(r(arguments[0]))return z(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,m(l)?l=h(l,0):o(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=z(n,u,i)))return j;if(B(j)||A(j))return j.set(l),j;for(g=p(l).getter,c=p(j).setter,b=0;b0){for(t=u(v(e.byteLength)),t=x(T.length-1,t),r=T[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = copy( defaults );\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '00d2k', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring user's don't do ill-advised things...\n\t\t\tget = arraylike2object( arr ).getter;\n\t\t\tset = arraylike2object( out ).setter;\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '00d33', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool' ;\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","copy","defaults","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","arraylike2object","getter","setter","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;4pEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,QAAS,gBAAiBP,EAAKI,gBAGxD,KARC,IAAIE,UAAWC,EAAQ,QAASN,ICtBzC,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,kHCcJG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,EAUzB,SAASK,EAAiBD,GACzB,OAASA,aAAeF,EA8BzB,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EAAOsB,EAAMC,GACRC,UAAUC,SACdJ,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOkB,EAAYC,EAAMC,EAAM5B,EAAKI,iBACpCgB,EAAS,EAETS,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB9B,EAAKI,eAC3C8B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOf,EAUR,SAASgB,EAAa3B,GACrB,IAAI4B,EACA1B,EAMJ,OAHAA,EAAIiB,EAAMnB,IAGDD,EAAKiB,QAAUjB,EAAMG,GAAIc,OAC1BjB,EAAMG,GAAI2B,MAGblB,EAAOX,EAAIT,EAAKI,cACb,MAERiC,EAAM,IAAIE,EAAa9B,GAGvBW,GAAUX,EAEH4B,GAYR,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,GAmB1B,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAxB,EACAP,EACAqC,EACAC,EACAN,EACA/B,EAUJ,GALCgC,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAO3B,EAAO6B,IAEb,MAAM,IAAIrC,UAAWC,EAAQ,QAASoC,IAEvC,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKpC,EAAsBmB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAzB,EAAMO,UAAW,IACPC,OACL0B,EAAmBlC,GACvBA,EAAMmC,EAAgBnC,EAAK,GAChBoC,EAAkBpC,GAC7BA,EAAMqC,EAAerC,EAAK,GACf,WAAWsC,KAAMZ,KAE5BD,GAAO,GAGK,QADbhC,EAAM8B,EAAYC,EAAMC,EAAKC,IAE5B,OAAOjC,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAIqC,IAAK9B,GACFP,EAKR,IAFAsC,EAAMQ,EAAkBvC,GAAMwC,OAC9BV,EAAMS,EAAkB9C,GAAMgD,OACxB/C,EAAI,EAAGA,EAAI+B,EAAK/B,IACrBoC,EAAKrC,EAAKC,EAAGqC,EAAK/B,EAAKN,IAExB,OAAOD,EAER,MAAM,IAAIJ,UAAWC,EAAQ,QAASiB,UAAW,KAiBlD,SAASO,IACR,IAAIe,EACApC,EACAiD,EACAhD,EAUJ,GAAa,QANZD,EADc,KADfoC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCmC,EADIzC,EAAiBR,GACf0C,EAAgB1C,EAAK,GAChBM,EAAgBN,GACrB4C,EAAe5C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAIgD,EAAIlC,OAAQd,IAC5BgD,EAAKhD,GAAM,EAGb,OAAOD,EAeR,SAASsB,EAAMK,GACd,IAAI5B,EACAmD,EACAjD,EACJ,GAAKkD,EAAkBxB,IAASA,EAAIyB,OACnCzB,EAAMA,EAAIyB,YACJ,IAAMC,EAAe1B,GAC3B,MAAM,IAAI/B,UAAWC,EAAQ,4EAA6E8B,IAE3G,GAAKA,EAAI2B,WAAa,EAAI,CAQzB,IAPAvD,EAAIwD,EAAOrC,EAAMS,EAAI2B,aAGrBvD,EAAIyD,EAAK1D,EAAKiB,OAAO,EAAGhB,GAGxBmD,EAAIpD,EAAMC,GACJE,EAAI,EAAGA,EAAIiD,EAAEnC,OAAQd,IAC1B,GAAKiD,EAAGjD,KAAQ0B,EACf,OAAO,EAITuB,EAAEhD,KAAMyB,GAET,OAAO,EAQR,SAASJ,IACR,IAAItB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKiB,OAAQd,IAC7BH,EAAMG,GAAIc,OAAS,EAEpBL,EAAS,GCjTR,IAAC+C,EAAiBhD,ICPrBU,EAAAuC,EAAA,UAAAjD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index efcf9f1..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 7d80d39132d67cfdec823b67015f32695634d8b5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 15:56:12 +0000 Subject: [PATCH 019/103] 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 | 43 +- benchmark/benchmark.calloc.js | 246 -- benchmark/benchmark.factory.js | 71 - benchmark/benchmark.js | 246 -- benchmark/benchmark.length.complex128.js | 102 - benchmark/benchmark.length.complex64.js | 102 - benchmark/benchmark.length.float32.js | 102 - benchmark/benchmark.length.float64.js | 102 - benchmark/benchmark.length.int16.js | 102 - benchmark/benchmark.length.int32.js | 102 - benchmark/benchmark.length.int8.js | 102 - benchmark/benchmark.length.uint16.js | 102 - benchmark/benchmark.length.uint32.js | 102 - benchmark/benchmark.length.uint8.js | 102 - benchmark/benchmark.length.uint8c.js | 102 - benchmark/benchmark.malloc.js | 246 -- branches.md | 53 - docs/repl.txt | 347 --- docs/types/test.ts | 193 -- examples/index.js | 80 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/bytes_per_element.json | 13 - lib/defaults.json | 3 - lib/factory.js | 370 --- lib/index.js | 56 - lib/main.js | 63 - lib/pool.js | 44 - lib/validate.js | 66 - package.json | 97 +- stats.html | 2689 +++++++++++++++++++++ test/test.factory.js | 2240 ----------------- test/test.js | 1797 -------------- 57 files changed, 2718 insertions(+), 10278 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.calloc.js delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.complex128.js delete mode 100644 benchmark/benchmark.length.complex64.js delete mode 100644 benchmark/benchmark.length.float32.js delete mode 100644 benchmark/benchmark.length.float64.js delete mode 100644 benchmark/benchmark.length.int16.js delete mode 100644 benchmark/benchmark.length.int32.js delete mode 100644 benchmark/benchmark.length.int8.js delete mode 100644 benchmark/benchmark.length.uint16.js delete mode 100644 benchmark/benchmark.length.uint32.js delete mode 100644 benchmark/benchmark.length.uint8.js delete mode 100644 benchmark/benchmark.length.uint8c.js delete mode 100644 benchmark/benchmark.malloc.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/bytes_per_element.json delete mode 100644 lib/defaults.json delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/pool.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index fe3add6..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-10-01T02:13:21.529Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ea35f20..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/array/pool) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 fc6d38a..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/array/pool) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 + + ```
@@ -482,7 +481,7 @@ console.log( 'nbytes: %d', typedarray.nbytes ); ## 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]. @@ -548,7 +547,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm diff --git a/benchmark/benchmark.calloc.js b/benchmark/benchmark.calloc.js deleted file mode 100644 index e5a1c77..0000000 --- a/benchmark/benchmark.calloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':calloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index f7cd676..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = typedarray.factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:highWaterMark', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'highWaterMark': 0 - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.highWaterMark = i; - f = typedarray.factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a023d2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.complex128.js b/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 47b623b..0000000 --- a/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex64.js b/benchmark/benchmark.length.complex64.js deleted file mode 100644 index 40a412b..0000000 --- a/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float32.js b/benchmark/benchmark.length.float32.js deleted file mode 100644 index 0227ed7..0000000 --- a/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float64.js b/benchmark/benchmark.length.float64.js deleted file mode 100644 index 2dbac1c..0000000 --- a/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int16.js b/benchmark/benchmark.length.int16.js deleted file mode 100644 index e2a8adc..0000000 --- a/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int32.js b/benchmark/benchmark.length.int32.js deleted file mode 100644 index e4df0aa..0000000 --- a/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int8.js b/benchmark/benchmark.length.int8.js deleted file mode 100644 index 7ceac11..0000000 --- a/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint16.js b/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 9a532b6..0000000 --- a/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint32.js b/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 98f2d7f..0000000 --- a/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8.js b/benchmark/benchmark.length.uint8.js deleted file mode 100644 index 8359249..0000000 --- a/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8c.js b/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index d47d023..0000000 --- a/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.malloc.js b/benchmark/benchmark.malloc.js deleted file mode 100644 index d4eea72..0000000 --- a/benchmark/benchmark.malloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':malloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 8fce14f..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/array/pool" -click B href "https://github.com/stdlib-js/array-pool/tree/main" -click C href "https://github.com/stdlib-js/array-pool/tree/production" -click D href "https://github.com/stdlib-js/array-pool/tree/esm" -click E href "https://github.com/stdlib-js/array-pool/tree/deno" -click F href "https://github.com/stdlib-js/array-pool/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/pool -[production-url]: https://github.com/stdlib-js/array-pool/tree/production -[deno-url]: https://github.com/stdlib-js/array-pool/tree/deno -[umd-url]: https://github.com/stdlib-js/array-pool/tree/umd -[esm-url]: https://github.com/stdlib-js/array-pool/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5244595..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,347 +0,0 @@ - -{{alias}}( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - Memory is **uninitialized**, which means that the contents of a returned - typed array may contain sensitive contents. - - The function supports the following data types: - - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - The default typed array data type is `float64`. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}() - [] - > arr = {{alias}}( 'float32' ) - [] - - -{{alias}}( length[, dtype] ) - Returns an uninitialized typed array having a specified length from a typed - array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > arr = {{alias}}( 5, 'int32' ) - - - -{{alias}}( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - This method shares the same security vulnerabilities mentioned above. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc() - - > arr = {{alias}}.malloc( 'float32' ) - - - -{{alias}}.malloc( length[, dtype] ) - Returns a typed array having a specified length from a typed array memory - pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc( 5 ) - - > arr = {{alias}}.malloc( 5, 'int32' ) - - - -{{alias}}.malloc( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}.malloc( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.calloc( [dtype] ) - Returns a zero-initialized typed array from a typed array memory pool. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc() - [] - > arr = {{alias}}.calloc( 'float32' ) - [] - - -{{alias}}.calloc( length[, dtype] ) - Returns a zero-initialized typed array having a specified length from a - typed array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}.calloc( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}.free( buf ) - Frees a typed array or typed array buffer for use in a future allocation. - - Parameters - ---------- - buf: TypedArray|ArrayBuffer - Typed array or typed array buffer to free. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ) - - -{{alias}}.clear() - Clears the typed array pool allowing garbage collection of previously - allocated (and currently free) array buffers. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - > {{alias}}.clear() - - -{{alias}}.highWaterMark - Read-only property returning the pool's high water mark. - - Once a high water mark is reached, typed array allocation fails. - - Examples - -------- - > {{alias}}.highWaterMark - - -{{alias}}.nbytes - Read-only property returning the total number of allocated bytes. - - The returned value is the total accumulated value. Hence, anytime a pool - must allocate a new array buffer (i.e., more memory), the pool increments - this value. - - The only time this value is decremented is when a pool is cleared. - - This behavior means that, while allocated buffers which are never freed may, - in fact, be garbage collected, they continue to count against the high water - mark limit. - - Accordingly, you should *always* free allocated buffers in order to prevent - the pool from believing that non-freed buffers are continually in use. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.nbytes - - -{{alias}}.factory( [options] ) - Creates a typed array pool. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.highWaterMark: integer (optional) - Maximum total memory (in bytes) which can be allocated. - - Returns - ------- - fcn: Function - Function for creating typed arrays from a typed array memory pool. - - Examples - -------- - > var pool = {{alias}}.factory(); - > var arr1 = pool( 3, 'float64' ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1014bba..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,193 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-empty */ -/* tslint:disable:no-unused-expression */ - -import typedarraypool = require( './index' ); - - -// TESTS // - -// The function returns a typed array or null... -{ - typedarraypool(); // $ExpectType TypedArrayOrNull - typedarraypool( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the function is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool( true ); // $ExpectError - typedarraypool( false ); // $ExpectError - typedarraypool( null ); // $ExpectError - typedarraypool( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized data type... -{ - typedarraypool( 4, true ); // $ExpectError - typedarraypool( 4, false ); // $ExpectError - typedarraypool( 4, null ); // $ExpectError - typedarraypool( 4, 'abc' ); // $ExpectError - typedarraypool( 4, 123 ); // $ExpectError - typedarraypool( 4, [] ); // $ExpectError - typedarraypool( 4, {} ); // $ExpectError - typedarraypool( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an incorrect number of arguments... -{ - typedarraypool( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `malloc` method which returns a typed array or null... -{ - typedarraypool.malloc(); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.malloc( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `malloc` method is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool.malloc( true ); // $ExpectError - typedarraypool.malloc( false ); // $ExpectError - typedarraypool.malloc( null ); // $ExpectError - typedarraypool.malloc( {} ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.malloc( 4, true ); // $ExpectError - typedarraypool.malloc( 4, false ); // $ExpectError - typedarraypool.malloc( 4, null ); // $ExpectError - typedarraypool.malloc( 4, 'abc' ); // $ExpectError - typedarraypool.malloc( 4, 123 ); // $ExpectError - typedarraypool.malloc( 4, [] ); // $ExpectError - typedarraypool.malloc( 4, {} ); // $ExpectError - typedarraypool.malloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided an incorrect number of arguments... -{ - typedarraypool.malloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `calloc` method which returns a typed array or null... -{ - typedarraypool.calloc(); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `calloc` method is provided a first argument which is not a number... -{ - typedarraypool.calloc( 'abc' ); // $ExpectError - typedarraypool.calloc( true ); // $ExpectError - typedarraypool.calloc( false ); // $ExpectError - typedarraypool.calloc( null ); // $ExpectError - typedarraypool.calloc( {} ); // $ExpectError - typedarraypool.calloc( [] ); // $ExpectError - typedarraypool.calloc( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.calloc( 4, true ); // $ExpectError - typedarraypool.calloc( 4, false ); // $ExpectError - typedarraypool.calloc( 4, null ); // $ExpectError - typedarraypool.calloc( 4, 'abc' ); // $ExpectError - typedarraypool.calloc( 4, 123 ); // $ExpectError - typedarraypool.calloc( 4, [] ); // $ExpectError - typedarraypool.calloc( 4, {} ); // $ExpectError - typedarraypool.calloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided an incorrect number of arguments... -{ - typedarraypool.calloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `factory` method which returns a typed array pool.. -{ - typedarraypool.factory(); // $ExpectType Pool - typedarraypool.factory( { 'highWaterMark': 556 } ); // $ExpectType Pool -} - -// The compiler throws an error if the `factory` method is provided a `highWaterMark` option which is not a number... -{ - typedarraypool.factory( { 'highWaterMark': true } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': false } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': 'abc' } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': null } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': [] } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': {} } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an incorrect number of arguments... -{ - typedarraypool.factory( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` method which returns void... -{ - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.free( arr ); // $ExpectType void -} - -// The compiler throws an error if the `free` method is provided a first argument which is neither a typed array nor array buffer... -{ - typedarraypool.free( true ); // $ExpectError - typedarraypool.free( false ); // $ExpectError - typedarraypool.free( 123 ); // $ExpectError - typedarraypool.free( 'abc' ); // $ExpectError - typedarraypool.free( null ); // $ExpectError - typedarraypool.free( {} ); // $ExpectError - typedarraypool.free( ( x: number ): number => x ); // $ExpectError -} - -// Attached to the main export is a `clear` method which returns void... -{ - typedarraypool.clear(); // $ExpectType void -} - -// The compiler throws an error if the `clear` method is provided arguments... -{ - typedarraypool.clear( {} ); // $ExpectError - typedarraypool.clear( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `highWaterMark` property... -{ - typedarraypool.highWaterMark; // $ExpectType number -} - -// Attached to the main export is a `nbytes` property... -{ - typedarraypool.nbytes; // $ExpectType number -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 24a7846..0000000 --- a/examples/index.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 randu = require( '@stdlib/random-base-randu' ); -var typedarraypool = require( './../lib' ); - -// Create a typed array pool which can allocate at most 1GB: -var typedarray = typedarraypool.factory({ - 'highWaterMark': 1e9 -}); - -// Inspect the pool: -console.log( 'Max bytes: %d', typedarray.highWaterMark ); -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Allocate an array for storing double-precision floating-point numbers: -var arr1 = typedarray( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Fill the array... -var i; -for ( i = 0; i < arr1.length; i++ ) { - arr1[ i ] = randu(); -} - -// Inspect array contents: -console.log( arr1 ); - -// Free the array: -typedarray.free( arr1 ); - -// Allocate another array similar to the previous one: -var arr2 = typedarray( 5, 'float64' ); -// returns - -// Check that we have been returned a new typed array view: -console.log( arr2 === arr1 ); -// => false - -// Inspect array contents: -console.log( arr2 ); - -// Free the array: -typedarray.free( arr2 ); - -// Allocate an initialized array: -var arr3 = typedarray.calloc( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect array contents: -console.log( arr3 ); - -// Free the array: -typedarray.free( arr3 ); - -// Clear the pool: -typedarray.clear(); - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 239fcdc..4500b91 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; import ArrayBuffer = require( '@stdlib/array-buffer' ); diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..55d247f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";var w={highWaterMark:9007199254740992};function M(e,t){return y(t)?k(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(f("00d35","highWaterMark",e.highWaterMark)):null:new TypeError(f("00d2h",t))}function W(e){var t,r;for(t=[],r=0;rL.highWaterMark?null:(t=new c(e),k+=e,t)}function z(e,t,r){var s;return 0===t?new e(0):null===(s=q(b(t)*E[r]))?s:new e(s,0,t)}function C(){var e,i,n,l,j,c,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(n=d(i)))throw new TypeError(f("00d2k",i));if(e<=0)return new n(0);if(r(arguments[0]))return z(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,m(l)?l=h(l,0):o(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=z(n,u,i)))return j;if(B(j)||A(j))return j.set(l),j;for(g=p(l).getter,c=p(j).setter,b=0;b0){for(t=u(v(e.byteLength)),t=x(T.length-1,t),r=T[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = copy( defaults );\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '00d2k', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring user's don't do ill-advised things...\n\t\t\tget = arraylike2object( arr ).getter;\n\t\t\tset = arraylike2object( out ).setter;\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '00d33', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool' ;\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","copy","defaults","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","arraylike2object","getter","setter","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;4pEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,QAAS,gBAAiBP,EAAKI,gBAGxD,KARC,IAAIE,UAAWC,EAAQ,QAASN,ICtBzC,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,kHCcJG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,EAUzB,SAASK,EAAiBD,GACzB,OAASA,aAAeF,EA8BzB,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EAAOsB,EAAMC,GACRC,UAAUC,SACdJ,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOkB,EAAYC,EAAMC,EAAM5B,EAAKI,iBACpCgB,EAAS,EAETS,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB9B,EAAKI,eAC3C8B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOf,EAUR,SAASgB,EAAa3B,GACrB,IAAI4B,EACA1B,EAMJ,OAHAA,EAAIiB,EAAMnB,IAGDD,EAAKiB,QAAUjB,EAAMG,GAAIc,OAC1BjB,EAAMG,GAAI2B,MAGblB,EAAOX,EAAIT,EAAKI,cACb,MAERiC,EAAM,IAAIE,EAAa9B,GAGvBW,GAAUX,EAEH4B,GAYR,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,GAmB1B,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAxB,EACAP,EACAqC,EACAC,EACAN,EACA/B,EAUJ,GALCgC,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAO3B,EAAO6B,IAEb,MAAM,IAAIrC,UAAWC,EAAQ,QAASoC,IAEvC,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKpC,EAAsBmB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAzB,EAAMO,UAAW,IACPC,OACL0B,EAAmBlC,GACvBA,EAAMmC,EAAgBnC,EAAK,GAChBoC,EAAkBpC,GAC7BA,EAAMqC,EAAerC,EAAK,GACf,WAAWsC,KAAMZ,KAE5BD,GAAO,GAGK,QADbhC,EAAM8B,EAAYC,EAAMC,EAAKC,IAE5B,OAAOjC,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAIqC,IAAK9B,GACFP,EAKR,IAFAsC,EAAMQ,EAAkBvC,GAAMwC,OAC9BV,EAAMS,EAAkB9C,GAAMgD,OACxB/C,EAAI,EAAGA,EAAI+B,EAAK/B,IACrBoC,EAAKrC,EAAKC,EAAGqC,EAAK/B,EAAKN,IAExB,OAAOD,EAER,MAAM,IAAIJ,UAAWC,EAAQ,QAASiB,UAAW,KAiBlD,SAASO,IACR,IAAIe,EACApC,EACAiD,EACAhD,EAUJ,GAAa,QANZD,EADc,KADfoC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCmC,EADIzC,EAAiBR,GACf0C,EAAgB1C,EAAK,GAChBM,EAAgBN,GACrB4C,EAAe5C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAIgD,EAAIlC,OAAQd,IAC5BgD,EAAKhD,GAAM,EAGb,OAAOD,EAeR,SAASsB,EAAMK,GACd,IAAI5B,EACAmD,EACAjD,EACJ,GAAKkD,EAAkBxB,IAASA,EAAIyB,OACnCzB,EAAMA,EAAIyB,YACJ,IAAMC,EAAe1B,GAC3B,MAAM,IAAI/B,UAAWC,EAAQ,4EAA6E8B,IAE3G,GAAKA,EAAI2B,WAAa,EAAI,CAQzB,IAPAvD,EAAIwD,EAAOrC,EAAMS,EAAI2B,aAGrBvD,EAAIyD,EAAK1D,EAAKiB,OAAO,EAAGhB,GAGxBmD,EAAIpD,EAAMC,GACJE,EAAI,EAAGA,EAAIiD,EAAEnC,OAAQd,IAC1B,GAAKiD,EAAGjD,KAAQ0B,EACf,OAAO,EAITuB,EAAEhD,KAAMyB,GAET,OAAO,EAQR,SAASJ,IACR,IAAItB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKiB,OAAQd,IAC7BH,EAAMG,GAAIc,OAAS,EAEpBL,EAAS,GCjTR,IAAC+C,EAAiBhD,ICPrBU,EAAAuC,EAAA,UAAAjD"} \ No newline at end of file diff --git a/lib/bytes_per_element.json b/lib/bytes_per_element.json deleted file mode 100644 index f97fe70..0000000 --- a/lib/bytes_per_element.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "float64": 8, - "float32": 4, - "int16": 2, - "int32": 4, - "int8": 1, - "uint16": 2, - "uint32": 4, - "uint8": 1, - "uint8c": 1, - "complex64": 8, - "complex128": 16 -} diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index c71c8f2..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "highWaterMark": 9007199254740992 -} diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index b75e403..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,370 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var isComplex64Array = require( '@stdlib/assert-is-complex64array' ); -var isComplex128Array = require( '@stdlib/assert-is-complex128array' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var ctors = require( '@stdlib/array-typed-ctors' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( '@stdlib/utils-copy' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil = require( '@stdlib/math-base-special-ceil' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); -var log2 = require( '@stdlib/math-base-special-log2' ); -var min = require( '@stdlib/math-base-special-min' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); -var createPool = require( './pool.js' ); -var BYTES_PER_ELEMENT = require( './bytes_per_element.json' ); - - -// VARIABLES // - -var Complex64Array = ctors( 'complex64' ); -var Complex128Array = ctors( 'complex128' ); - - -// FUNCTIONS // - -/** -* Tests whether an array is a single-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a single-precision complex floating-point number array -*/ -function isCmplx64Array( arr ) { - return ( arr instanceof Complex64Array ); -} - -/** -* Tests whether an array is a double-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a double-precision complex floating-point number array -*/ -function isCmplx128Array( arr ) { - return ( arr instanceof Complex128Array ); -} - - -// MAIN // - -/** -* Creates a typed array pool. -* -* @param {Options} [options] - pool options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} allocator -* -* @example -* var typedarraypool = factory(); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -function factory( options ) { - var nbytes; - var pool; - var opts; - var err; - - opts = copy( defaults ); - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - pool = createPool( ceil( log2( opts.highWaterMark ) ) ); - nbytes = 0; - - setReadOnly( malloc, 'malloc', malloc ); // circular reference - setReadOnly( malloc, 'calloc', calloc ); - setReadOnly( malloc, 'free', free ); - setReadOnly( malloc, 'clear', clear ); - setReadOnly( malloc, 'highWaterMark', opts.highWaterMark ); - setReadOnlyAccessor( malloc, 'nbytes', getBytes ); - - return malloc; - - /** - * Returns the number of allocated bytes. - * - * @private - * @returns {NonNegativeInteger} number of allocated bytes - */ - function getBytes() { - return nbytes; - } - - /** - * Returns an array buffer. - * - * @private - * @param {NonNegativeInteger} n - number of bytes - * @returns {(ArrayBuffer|null)} array buffer or null - */ - function arraybuffer( n ) { - var buf; - var i; - - // Convert the number of bytes to an index in our pool table: - i = log2( n ); - - // If we already have an available array buffer, use it... - if ( i < pool.length && pool[ i ].length ) { - return pool[ i ].pop(); - } - // Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate... - if ( nbytes+n > opts.highWaterMark ) { - return null; - } - buf = new ArrayBuffer( n ); - - // Update the running counter of allocated bytes: - nbytes += n; - - return buf; - } - - /** - * Returns a typed array. - * - * @private - * @param {Function} ctor - typed array constructor - * @param {NonNegativeInteger} len - view length - * @param {string} dtype - data type - * @returns {(TypedArray|null)} typed array or null - */ - function typedarray( ctor, len, dtype ) { - var buf; - if ( len === 0 ) { - return new ctor( 0 ); - } - buf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] ); - if ( buf === null ) { - return buf; - } - return new ctor( buf, 0, len ); - } - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length or an array-like object - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function malloc() { - var nargs; - var dtype; - var ctor; - var arr; - var out; - var set; - var get; - var len; - var i; - - nargs = arguments.length; - if ( nargs && isString( arguments[ nargs-1 ] ) ) { - nargs -= 1; - dtype = arguments[ nargs ]; - } else { - dtype = 'float64'; - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( '00d2k', dtype ) ); - } - if ( nargs <= 0 ) { - return new ctor( 0 ); - } - // Check if provided a typed array length... - if ( isNonNegativeInteger( arguments[ 0 ] ) ) { - return typedarray( ctor, arguments[ 0 ], dtype ); - } - // Check if provided an array-like object containing data elements... - if ( isCollection( arguments[ 0 ] ) ) { - arr = arguments[ 0 ]; - len = arr.length; - if ( isComplex128Array( arr ) ) { - arr = reinterpret128( arr, 0 ); - } else if ( isComplex64Array( arr ) ) { - arr = reinterpret64( arr, 0 ); - } else if ( /^complex/.test( dtype ) ) { - // Assume we've been provided an array of interleaved real and imaginary components... - len /= 2; - } - out = typedarray( ctor, len, dtype ); - if ( out === null ) { - return out; - } - if ( isCmplx128Array( out ) || isCmplx64Array( out ) ) { - out.set( arr ); - return out; - } - // Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other "unsafe" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring user's don't do ill-advised things... - get = arraylike2object( arr ).getter; - set = arraylike2object( out ).setter; - for ( i = 0; i < len; i++ ) { - set( out, i, get( arr, i ) ); - } - return out; - } - throw new TypeError( format( '00d33', arguments[ 0 ] ) ); - } - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {NonNegativeInteger} [len=0] - array length - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function calloc() { - var nargs; - var out; - var tmp; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - out = malloc(); - } else if ( nargs === 1 ) { - out = malloc( arguments[ 0 ] ); - } else { - out = malloc( arguments[ 0 ], arguments[ 1 ] ); - } - if ( out !== null ) { - // Initialize the memory... - if ( isCmplx128Array( out ) ) { - tmp = reinterpret128( out, 0 ); - } else if ( isCmplx64Array( out ) ) { - tmp = reinterpret64( out, 0 ); - } else { - tmp = out; - } - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = 0.0; - } - } - return out; - } - - /** - * Frees a typed array or typed array buffer. - * - * ## Notes - * - * - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., "freeing" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool. - * - * @private - * @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free - * @throws {TypeError} must provide a typed array or typed array buffer - * @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed - */ - function free( buf ) { - var n; - var p; - var i; - if ( isTypedArrayLike( buf ) && buf.buffer ) { - buf = buf.buffer; - } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) ); - } - if ( buf.byteLength > 0 ) { - n = floor( log2( buf.byteLength ) ); - - // Prohibit "freeing" array buffers which would potentially allow users to circumvent high water mark limits: - n = min( pool.length-1, n ); - - // Ensure that we do not attempt to free the same buffer more than once... - p = pool[ n ]; - for ( i = 0; i < p.length; i++ ) { - if ( p[ i ] === buf ) { - return false; - } - } - // Add the buffer to our pool of free buffers: - p.push( buf ); - } - return true; - } - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @private - */ - function clear() { - var i; - for ( i = 0; i < pool.length; i++ ) { - pool[ i ].length = 0; - } - nbytes = 0; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6c12a4e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Typed array pool. -* -* @module @stdlib/array-pool -* -* @example -* var typedarraypool = require( '@stdlib/array-pool' ); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8f69ee3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,63 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @name typedarraypool -* @type {Function} -* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a valid array length or an array-like object -* @throws {TypeError} must provide a recognized data type -* @returns {(TypedArray|null)} typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -var typedarraypool = factory(); - - -// EXPORTS // - -module.exports = typedarraypool; diff --git a/lib/pool.js b/lib/pool.js deleted file mode 100644 index 5abd287..0000000 --- a/lib/pool.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Initializes a cache for pooled typed array buffers. -* -* @private -* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size -* @returns {ArrayArray} initialized cache -*/ -function pool( n ) { - var out; - var i; - - out = []; - for ( i = 0; i < n+1; i++ ) { - out.push( [] ); - } - return out; -} - - -// EXPORTS // - -module.exports = pool; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 4135ec9..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'highWaterMark': 1024 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '00d2h', options ) ); - } - if ( hasOwnProp( options, 'highWaterMark' ) ) { - opts.highWaterMark = options.highWaterMark; - if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( '00d35', 'highWaterMark', opts.highWaterMark ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 558fca7..42614cf 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Typed array pool.", "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,76 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.0.x", - "@stdlib/array-buffer": "^0.0.x", - "@stdlib/array-typed-ctors": "^0.0.x", - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-arraybuffer": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-complex128array": "^0.0.x", - "@stdlib/assert-is-complex64array": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/assert-is-typed-array-like": "^0.0.x", - "@stdlib/math-base-special-ceil": "^0.0.x", - "@stdlib/math-base-special-ceil2": "^0.0.x", - "@stdlib/math-base-special-floor": "^0.0.x", - "@stdlib/math-base-special-log2": "^0.0.x", - "@stdlib/math-base-special-min": "^0.0.x", - "@stdlib/strided-base-reinterpret-complex128": "^0.0.x", - "@stdlib/strided-base-reinterpret-complex64": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-copy": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.0.x", - "@stdlib/array-complex64": "^0.0.x", - "@stdlib/array-float32": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/array-int16": "^0.0.x", - "@stdlib/array-int32": "^0.0.x", - "@stdlib/array-int8": "^0.0.x", - "@stdlib/array-uint16": "^0.0.x", - "@stdlib/array-uint32": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/array-uint8c": "^0.0.x", - "@stdlib/assert-instance-of": "^0.0.x", - "@stdlib/assert-is-complex-typed-array": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-typed-array": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/complex-float32": "^0.0.x", - "@stdlib/complex-float64": "^0.0.x", - "@stdlib/complex-imag": "^0.0.x", - "@stdlib/complex-imagf": "^0.0.x", - "@stdlib/complex-real": "^0.0.x", - "@stdlib/complex-realf": "^0.0.x", - "@stdlib/math-base-special-pow": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a520042 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 396aee2..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,2240 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function (no options)', function test( t ) { - t.strictEqual( typeof factory(), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - t.strictEqual( typeof factory( {} ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided a `highWaterMark` option which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (length)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a function which returns a typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, length)', function test( t ) { - var typedarraypool = factory(); - var arr; - - arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a `malloc` method which is a circular reference', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - var buf; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the returned function is a property which returns the pool\'s high water mark', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function supports specifying a high water mark which limits the total amount of memory a pool can allocate', function test( t ) { - var typedarraypool; - var arr1; - var arr2; - - typedarraypool = factory({ - 'highWaterMark': 64 // bytes - }); - - typedarraypool.clear(); - - arr1 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr1.length, 8, 'returns expected value' ); - t.strictEqual( arr1.byteLength, 64, 'returns expected value' ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - typedarraypool.free( arr1 ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Create an array which is less than or equal to the high water mark: - arr2 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr2.length, 8, 'returns expected value' ); - t.strictEqual( arr2.byteLength, 64, 'returns expected value' ); - - typedarraypool.free( arr2 ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a property which returns the total number of accumulated bytes', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var typedarraypool; - var arrs; - var i; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 54aa5ee..0000000 --- a/test/test.js +++ /dev/null @@ -1,1797 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var typedarraypool = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -}); From 63167c69d90c0d22d4c5244f2267c2ac104cd40c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 02:00:26 +0000 Subject: [PATCH 020/103] Transform error messages --- lib/factory.js | 6 +++--- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 2401100..b75e403 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -33,7 +33,7 @@ var ctors = require( '@stdlib/array-typed-ctors' ); var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( '@stdlib/utils-copy' ); var ArrayBuffer = require( '@stdlib/array-buffer' ); var ceil = require( '@stdlib/math-base-special-ceil' ); @@ -226,7 +226,7 @@ function factory( options ) { } ctor = ctors( dtype ); if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '00d2k', dtype ) ); } if ( nargs <= 0 ) { return new ctor( 0 ); @@ -263,7 +263,7 @@ function factory( options ) { } return out; } - throw new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) ); + throw new TypeError( format( '00d33', arguments[ 0 ] ) ); } /** diff --git a/lib/validate.js b/lib/validate.js index ce54890..4135ec9 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '00d2h', options ) ); } if ( hasOwnProp( options, 'highWaterMark' ) ) { opts.highWaterMark = options.highWaterMark; if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) ); + return new TypeError( format( '00d35', 'highWaterMark', opts.highWaterMark ) ); } } return null; diff --git a/package.json b/package.json index 50986ed..558fca7 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "@stdlib/math-base-special-min": "^0.0.x", "@stdlib/strided-base-reinterpret-complex128": "^0.0.x", "@stdlib/strided-base-reinterpret-complex64": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-copy": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", From 5f1d6a7920bfd02e99719720ded65250ecfb3b9e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 18:16:42 +0000 Subject: [PATCH 021/103] Remove files --- index.d.ts | 359 ------- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 3053 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 4500b91..0000000 --- a/index.d.ts +++ /dev/null @@ -1,359 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; -import ArrayBuffer = require( '@stdlib/array-buffer' ); - -/** -* Typed array or null. -*/ -type TypedArrayOrNull = RealOrComplexTypedArray | null; - -/** -* Interface defining pool options. -*/ -interface Options { - /** - * Maximum total memory which can be allocated. - */ - highWaterMark?: number; -} - -/** -* Pool interface. -*/ -interface Pool { - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr = typedarraypool(); - * // returns [] - * - * @example - * var arr = typedarraypool( 'float32' ); - * // returns [] - */ - ( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * // Allocate an array of doubles: - * var arr = typedarraypool( 5, 'float64' ); - * // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * typedarraypool.free( arr ); - * - * @example - * var arr1 = typedarraypool( [ 0.5, 0.5, 0.5 ] ); - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * @example - * var arr1 = [ 0.5, 0.5, 0.5 ]; - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - */ - ( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc(); - * // returns [] - * - * var arr2 = typedarraypool.calloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param length - typed array length - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc( 5 ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * var arr2 = typedarraypool.calloc( 5, 'uint8' ); - * // returns [ 0, 0, 0, 0, 0 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( length: number, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc(); - * // returns [] - * - * var arr2 = typedarraypool.malloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc( 5 ); - * // returns - * - * var arr2 = typedarraypool.malloc( 5, 'uint8' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 5.0, -3.0, 2.0 ] ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr2 = typedarraypool.malloc( arr1 ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr3 = typedarraypool.malloc( arr1, 'int32' ); - * // returns [ 5, -3, 2 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * typedarraypool.free( arr3 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ] ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * var arr2 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ], 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Frees a typed array or typed array buffer for use in a future allocation. - * - * @param buf - typed array or typed array buffer to free - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array for use in a future allocation: - * typedarraypool.free( arr ); - * - * // Create another typed array: - * arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array buffer for use in a future allocation: - * typedarraypool.free( arr.buffer ); - */ - free( buf: RealOrComplexTypedArray | ArrayBuffer ): void; - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr ); - * - * // ... - * - * // Clear all freed buffers: - * typedarraypool.clear(); - */ - clear(): void; - - /** - * Read-only property returning the pool's high water mark. - * - * ## Notes - * - * - Once a high water mark is reached, typed array allocation fails. - * - * @example - * var limit = typedarraypool.highWaterMark; - * // returns - */ - readonly highWaterMark: number; - - /** - * Read-only property returning the total number of allocated bytes. - * - * @example - * var arr = typedarraypool( 5, 'float64' ); - * - * var nbytes = typedarraypool.nbytes; - * // returns - */ - readonly nbytes: number; - - /** - * Creates a typed array pool. - * - * @param options - pool options - * @param options.highWaterMark - maximum total memory which can be allocated - * @throws must provide valid options - * @returns allocator - * - * @example - * var allocator = typedarraypool.factory(); - * - * // Allocate an array of doubles: - * var arr = allocator( 5, 'float64' ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * allocator.free( arr ); - */ - factory( options?: Options ): Pool; -} - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @param arg - an array length or an array-like object -* @param dtype - data type (default: 'float64') -* @returns typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -declare var typedarraypool: Pool; - - -// EXPORTS // - -export = typedarraypool; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 55d247f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";var w={highWaterMark:9007199254740992};function M(e,t){return y(t)?k(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(f("00d35","highWaterMark",e.highWaterMark)):null:new TypeError(f("00d2h",t))}function W(e){var t,r;for(t=[],r=0;rL.highWaterMark?null:(t=new c(e),k+=e,t)}function z(e,t,r){var s;return 0===t?new e(0):null===(s=q(b(t)*E[r]))?s:new e(s,0,t)}function C(){var e,i,n,l,j,c,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(n=d(i)))throw new TypeError(f("00d2k",i));if(e<=0)return new n(0);if(r(arguments[0]))return z(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,m(l)?l=h(l,0):o(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=z(n,u,i)))return j;if(B(j)||A(j))return j.set(l),j;for(g=p(l).getter,c=p(j).setter,b=0;b0){for(t=u(v(e.byteLength)),t=x(T.length-1,t),r=T[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = copy( defaults );\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '00d2k', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring user's don't do ill-advised things...\n\t\t\tget = arraylike2object( arr ).getter;\n\t\t\tset = arraylike2object( out ).setter;\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '00d33', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool' ;\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","copy","defaults","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","arraylike2object","getter","setter","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;4pEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,QAAS,gBAAiBP,EAAKI,gBAGxD,KARC,IAAIE,UAAWC,EAAQ,QAASN,ICtBzC,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,kHCcJG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,EAUzB,SAASK,EAAiBD,GACzB,OAASA,aAAeF,EA8BzB,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EAAOsB,EAAMC,GACRC,UAAUC,SACdJ,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOkB,EAAYC,EAAMC,EAAM5B,EAAKI,iBACpCgB,EAAS,EAETS,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB9B,EAAKI,eAC3C8B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOf,EAUR,SAASgB,EAAa3B,GACrB,IAAI4B,EACA1B,EAMJ,OAHAA,EAAIiB,EAAMnB,IAGDD,EAAKiB,QAAUjB,EAAMG,GAAIc,OAC1BjB,EAAMG,GAAI2B,MAGblB,EAAOX,EAAIT,EAAKI,cACb,MAERiC,EAAM,IAAIE,EAAa9B,GAGvBW,GAAUX,EAEH4B,GAYR,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,GAmB1B,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAxB,EACAP,EACAqC,EACAC,EACAN,EACA/B,EAUJ,GALCgC,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAO3B,EAAO6B,IAEb,MAAM,IAAIrC,UAAWC,EAAQ,QAASoC,IAEvC,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKpC,EAAsBmB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAzB,EAAMO,UAAW,IACPC,OACL0B,EAAmBlC,GACvBA,EAAMmC,EAAgBnC,EAAK,GAChBoC,EAAkBpC,GAC7BA,EAAMqC,EAAerC,EAAK,GACf,WAAWsC,KAAMZ,KAE5BD,GAAO,GAGK,QADbhC,EAAM8B,EAAYC,EAAMC,EAAKC,IAE5B,OAAOjC,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAIqC,IAAK9B,GACFP,EAKR,IAFAsC,EAAMQ,EAAkBvC,GAAMwC,OAC9BV,EAAMS,EAAkB9C,GAAMgD,OACxB/C,EAAI,EAAGA,EAAI+B,EAAK/B,IACrBoC,EAAKrC,EAAKC,EAAGqC,EAAK/B,EAAKN,IAExB,OAAOD,EAER,MAAM,IAAIJ,UAAWC,EAAQ,QAASiB,UAAW,KAiBlD,SAASO,IACR,IAAIe,EACApC,EACAiD,EACAhD,EAUJ,GAAa,QANZD,EADc,KADfoC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCmC,EADIzC,EAAiBR,GACf0C,EAAgB1C,EAAK,GAChBM,EAAgBN,GACrB4C,EAAe5C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAIgD,EAAIlC,OAAQd,IAC5BgD,EAAKhD,GAAM,EAGb,OAAOD,EAeR,SAASsB,EAAMK,GACd,IAAI5B,EACAmD,EACAjD,EACJ,GAAKkD,EAAkBxB,IAASA,EAAIyB,OACnCzB,EAAMA,EAAIyB,YACJ,IAAMC,EAAe1B,GAC3B,MAAM,IAAI/B,UAAWC,EAAQ,4EAA6E8B,IAE3G,GAAKA,EAAI2B,WAAa,EAAI,CAQzB,IAPAvD,EAAIwD,EAAOrC,EAAMS,EAAI2B,aAGrBvD,EAAIyD,EAAK1D,EAAKiB,OAAO,EAAGhB,GAGxBmD,EAAIpD,EAAMC,GACJE,EAAI,EAAGA,EAAIiD,EAAEnC,OAAQd,IAC1B,GAAKiD,EAAGjD,KAAQ0B,EACf,OAAO,EAITuB,EAAEhD,KAAMyB,GAET,OAAO,EAQR,SAASJ,IACR,IAAItB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKiB,OAAQd,IAC7BH,EAAMG,GAAIc,OAAS,EAEpBL,EAAS,GCjTR,IAAC+C,EAAiBhD,ICPrBU,EAAAuC,EAAA,UAAAjD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a520042..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 8ee4959b1fe216167c4c6e9c02bef7935b826da8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 18:17:40 +0000 Subject: [PATCH 022/103] 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 | 43 +- benchmark/benchmark.calloc.js | 246 -- benchmark/benchmark.factory.js | 71 - benchmark/benchmark.js | 246 -- benchmark/benchmark.length.complex128.js | 102 - benchmark/benchmark.length.complex64.js | 102 - benchmark/benchmark.length.float32.js | 102 - benchmark/benchmark.length.float64.js | 102 - benchmark/benchmark.length.int16.js | 102 - benchmark/benchmark.length.int32.js | 102 - benchmark/benchmark.length.int8.js | 102 - benchmark/benchmark.length.uint16.js | 102 - benchmark/benchmark.length.uint32.js | 102 - benchmark/benchmark.length.uint8.js | 102 - benchmark/benchmark.length.uint8c.js | 102 - benchmark/benchmark.malloc.js | 246 -- branches.md | 53 - docs/repl.txt | 347 -- docs/types/test.ts | 193 - examples/index.js | 80 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/bytes_per_element.json | 13 - lib/defaults.json | 3 - lib/factory.js | 370 -- lib/index.js | 56 - lib/main.js | 63 - lib/pool.js | 44 - lib/validate.js | 66 - package.json | 97 +- stats.html | 4044 +++++++++++++++++++++ test/test.factory.js | 2240 ------------ test/test.js | 1797 --------- 57 files changed, 4073 insertions(+), 10278 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.calloc.js delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.complex128.js delete mode 100644 benchmark/benchmark.length.complex64.js delete mode 100644 benchmark/benchmark.length.float32.js delete mode 100644 benchmark/benchmark.length.float64.js delete mode 100644 benchmark/benchmark.length.int16.js delete mode 100644 benchmark/benchmark.length.int32.js delete mode 100644 benchmark/benchmark.length.int8.js delete mode 100644 benchmark/benchmark.length.uint16.js delete mode 100644 benchmark/benchmark.length.uint32.js delete mode 100644 benchmark/benchmark.length.uint8.js delete mode 100644 benchmark/benchmark.length.uint8c.js delete mode 100644 benchmark/benchmark.malloc.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/bytes_per_element.json delete mode 100644 lib/defaults.json delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/pool.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index ec88af9..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-01T01:58:31.406Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ea35f20..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/array/pool) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 fc6d38a..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/array/pool) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 9ef1395..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9113bfe..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -482,7 +481,7 @@ console.log( 'nbytes: %d', typedarray.nbytes ); ## 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]. @@ -548,7 +547,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm diff --git a/benchmark/benchmark.calloc.js b/benchmark/benchmark.calloc.js deleted file mode 100644 index e5a1c77..0000000 --- a/benchmark/benchmark.calloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':calloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index f7cd676..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = typedarray.factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:highWaterMark', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'highWaterMark': 0 - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.highWaterMark = i; - f = typedarray.factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a023d2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.complex128.js b/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 47b623b..0000000 --- a/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex64.js b/benchmark/benchmark.length.complex64.js deleted file mode 100644 index 40a412b..0000000 --- a/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float32.js b/benchmark/benchmark.length.float32.js deleted file mode 100644 index 0227ed7..0000000 --- a/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float64.js b/benchmark/benchmark.length.float64.js deleted file mode 100644 index 2dbac1c..0000000 --- a/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int16.js b/benchmark/benchmark.length.int16.js deleted file mode 100644 index e2a8adc..0000000 --- a/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int32.js b/benchmark/benchmark.length.int32.js deleted file mode 100644 index e4df0aa..0000000 --- a/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int8.js b/benchmark/benchmark.length.int8.js deleted file mode 100644 index 7ceac11..0000000 --- a/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint16.js b/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 9a532b6..0000000 --- a/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint32.js b/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 98f2d7f..0000000 --- a/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8.js b/benchmark/benchmark.length.uint8.js deleted file mode 100644 index 8359249..0000000 --- a/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8c.js b/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index d47d023..0000000 --- a/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.malloc.js b/benchmark/benchmark.malloc.js deleted file mode 100644 index d4eea72..0000000 --- a/benchmark/benchmark.malloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':malloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 8fce14f..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/array/pool" -click B href "https://github.com/stdlib-js/array-pool/tree/main" -click C href "https://github.com/stdlib-js/array-pool/tree/production" -click D href "https://github.com/stdlib-js/array-pool/tree/esm" -click E href "https://github.com/stdlib-js/array-pool/tree/deno" -click F href "https://github.com/stdlib-js/array-pool/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/pool -[production-url]: https://github.com/stdlib-js/array-pool/tree/production -[deno-url]: https://github.com/stdlib-js/array-pool/tree/deno -[umd-url]: https://github.com/stdlib-js/array-pool/tree/umd -[esm-url]: https://github.com/stdlib-js/array-pool/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5244595..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,347 +0,0 @@ - -{{alias}}( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - Memory is **uninitialized**, which means that the contents of a returned - typed array may contain sensitive contents. - - The function supports the following data types: - - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - The default typed array data type is `float64`. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}() - [] - > arr = {{alias}}( 'float32' ) - [] - - -{{alias}}( length[, dtype] ) - Returns an uninitialized typed array having a specified length from a typed - array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > arr = {{alias}}( 5, 'int32' ) - - - -{{alias}}( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - This method shares the same security vulnerabilities mentioned above. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc() - - > arr = {{alias}}.malloc( 'float32' ) - - - -{{alias}}.malloc( length[, dtype] ) - Returns a typed array having a specified length from a typed array memory - pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc( 5 ) - - > arr = {{alias}}.malloc( 5, 'int32' ) - - - -{{alias}}.malloc( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}.malloc( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.calloc( [dtype] ) - Returns a zero-initialized typed array from a typed array memory pool. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc() - [] - > arr = {{alias}}.calloc( 'float32' ) - [] - - -{{alias}}.calloc( length[, dtype] ) - Returns a zero-initialized typed array having a specified length from a - typed array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}.calloc( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}.free( buf ) - Frees a typed array or typed array buffer for use in a future allocation. - - Parameters - ---------- - buf: TypedArray|ArrayBuffer - Typed array or typed array buffer to free. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ) - - -{{alias}}.clear() - Clears the typed array pool allowing garbage collection of previously - allocated (and currently free) array buffers. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - > {{alias}}.clear() - - -{{alias}}.highWaterMark - Read-only property returning the pool's high water mark. - - Once a high water mark is reached, typed array allocation fails. - - Examples - -------- - > {{alias}}.highWaterMark - - -{{alias}}.nbytes - Read-only property returning the total number of allocated bytes. - - The returned value is the total accumulated value. Hence, anytime a pool - must allocate a new array buffer (i.e., more memory), the pool increments - this value. - - The only time this value is decremented is when a pool is cleared. - - This behavior means that, while allocated buffers which are never freed may, - in fact, be garbage collected, they continue to count against the high water - mark limit. - - Accordingly, you should *always* free allocated buffers in order to prevent - the pool from believing that non-freed buffers are continually in use. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.nbytes - - -{{alias}}.factory( [options] ) - Creates a typed array pool. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.highWaterMark: integer (optional) - Maximum total memory (in bytes) which can be allocated. - - Returns - ------- - fcn: Function - Function for creating typed arrays from a typed array memory pool. - - Examples - -------- - > var pool = {{alias}}.factory(); - > var arr1 = pool( 3, 'float64' ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1014bba..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,193 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-empty */ -/* tslint:disable:no-unused-expression */ - -import typedarraypool = require( './index' ); - - -// TESTS // - -// The function returns a typed array or null... -{ - typedarraypool(); // $ExpectType TypedArrayOrNull - typedarraypool( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the function is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool( true ); // $ExpectError - typedarraypool( false ); // $ExpectError - typedarraypool( null ); // $ExpectError - typedarraypool( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized data type... -{ - typedarraypool( 4, true ); // $ExpectError - typedarraypool( 4, false ); // $ExpectError - typedarraypool( 4, null ); // $ExpectError - typedarraypool( 4, 'abc' ); // $ExpectError - typedarraypool( 4, 123 ); // $ExpectError - typedarraypool( 4, [] ); // $ExpectError - typedarraypool( 4, {} ); // $ExpectError - typedarraypool( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an incorrect number of arguments... -{ - typedarraypool( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `malloc` method which returns a typed array or null... -{ - typedarraypool.malloc(); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.malloc( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `malloc` method is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool.malloc( true ); // $ExpectError - typedarraypool.malloc( false ); // $ExpectError - typedarraypool.malloc( null ); // $ExpectError - typedarraypool.malloc( {} ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.malloc( 4, true ); // $ExpectError - typedarraypool.malloc( 4, false ); // $ExpectError - typedarraypool.malloc( 4, null ); // $ExpectError - typedarraypool.malloc( 4, 'abc' ); // $ExpectError - typedarraypool.malloc( 4, 123 ); // $ExpectError - typedarraypool.malloc( 4, [] ); // $ExpectError - typedarraypool.malloc( 4, {} ); // $ExpectError - typedarraypool.malloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided an incorrect number of arguments... -{ - typedarraypool.malloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `calloc` method which returns a typed array or null... -{ - typedarraypool.calloc(); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `calloc` method is provided a first argument which is not a number... -{ - typedarraypool.calloc( 'abc' ); // $ExpectError - typedarraypool.calloc( true ); // $ExpectError - typedarraypool.calloc( false ); // $ExpectError - typedarraypool.calloc( null ); // $ExpectError - typedarraypool.calloc( {} ); // $ExpectError - typedarraypool.calloc( [] ); // $ExpectError - typedarraypool.calloc( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.calloc( 4, true ); // $ExpectError - typedarraypool.calloc( 4, false ); // $ExpectError - typedarraypool.calloc( 4, null ); // $ExpectError - typedarraypool.calloc( 4, 'abc' ); // $ExpectError - typedarraypool.calloc( 4, 123 ); // $ExpectError - typedarraypool.calloc( 4, [] ); // $ExpectError - typedarraypool.calloc( 4, {} ); // $ExpectError - typedarraypool.calloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided an incorrect number of arguments... -{ - typedarraypool.calloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `factory` method which returns a typed array pool.. -{ - typedarraypool.factory(); // $ExpectType Pool - typedarraypool.factory( { 'highWaterMark': 556 } ); // $ExpectType Pool -} - -// The compiler throws an error if the `factory` method is provided a `highWaterMark` option which is not a number... -{ - typedarraypool.factory( { 'highWaterMark': true } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': false } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': 'abc' } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': null } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': [] } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': {} } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an incorrect number of arguments... -{ - typedarraypool.factory( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` method which returns void... -{ - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.free( arr ); // $ExpectType void -} - -// The compiler throws an error if the `free` method is provided a first argument which is neither a typed array nor array buffer... -{ - typedarraypool.free( true ); // $ExpectError - typedarraypool.free( false ); // $ExpectError - typedarraypool.free( 123 ); // $ExpectError - typedarraypool.free( 'abc' ); // $ExpectError - typedarraypool.free( null ); // $ExpectError - typedarraypool.free( {} ); // $ExpectError - typedarraypool.free( ( x: number ): number => x ); // $ExpectError -} - -// Attached to the main export is a `clear` method which returns void... -{ - typedarraypool.clear(); // $ExpectType void -} - -// The compiler throws an error if the `clear` method is provided arguments... -{ - typedarraypool.clear( {} ); // $ExpectError - typedarraypool.clear( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `highWaterMark` property... -{ - typedarraypool.highWaterMark; // $ExpectType number -} - -// Attached to the main export is a `nbytes` property... -{ - typedarraypool.nbytes; // $ExpectType number -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 24a7846..0000000 --- a/examples/index.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 randu = require( '@stdlib/random-base-randu' ); -var typedarraypool = require( './../lib' ); - -// Create a typed array pool which can allocate at most 1GB: -var typedarray = typedarraypool.factory({ - 'highWaterMark': 1e9 -}); - -// Inspect the pool: -console.log( 'Max bytes: %d', typedarray.highWaterMark ); -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Allocate an array for storing double-precision floating-point numbers: -var arr1 = typedarray( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Fill the array... -var i; -for ( i = 0; i < arr1.length; i++ ) { - arr1[ i ] = randu(); -} - -// Inspect array contents: -console.log( arr1 ); - -// Free the array: -typedarray.free( arr1 ); - -// Allocate another array similar to the previous one: -var arr2 = typedarray( 5, 'float64' ); -// returns - -// Check that we have been returned a new typed array view: -console.log( arr2 === arr1 ); -// => false - -// Inspect array contents: -console.log( arr2 ); - -// Free the array: -typedarray.free( arr2 ); - -// Allocate an initialized array: -var arr3 = typedarray.calloc( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect array contents: -console.log( arr3 ); - -// Free the array: -typedarray.free( arr3 ); - -// Clear the pool: -typedarray.clear(); - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 239fcdc..4500b91 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; import ArrayBuffer = require( '@stdlib/array-buffer' ); diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..55d247f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";var w={highWaterMark:9007199254740992};function M(e,t){return y(t)?k(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(f("00d35","highWaterMark",e.highWaterMark)):null:new TypeError(f("00d2h",t))}function W(e){var t,r;for(t=[],r=0;rL.highWaterMark?null:(t=new c(e),k+=e,t)}function z(e,t,r){var s;return 0===t?new e(0):null===(s=q(b(t)*E[r]))?s:new e(s,0,t)}function C(){var e,i,n,l,j,c,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(n=d(i)))throw new TypeError(f("00d2k",i));if(e<=0)return new n(0);if(r(arguments[0]))return z(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,m(l)?l=h(l,0):o(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=z(n,u,i)))return j;if(B(j)||A(j))return j.set(l),j;for(g=p(l).getter,c=p(j).setter,b=0;b0){for(t=u(v(e.byteLength)),t=x(T.length-1,t),r=T[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = copy( defaults );\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '00d2k', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring user's don't do ill-advised things...\n\t\t\tget = arraylike2object( arr ).getter;\n\t\t\tset = arraylike2object( out ).setter;\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '00d33', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool' ;\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","copy","defaults","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","arraylike2object","getter","setter","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;4pEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,QAAS,gBAAiBP,EAAKI,gBAGxD,KARC,IAAIE,UAAWC,EAAQ,QAASN,GASzC,CC/BA,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,iHCaIG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EAAOsB,EAAMC,GACRC,UAAUC,SACdJ,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOkB,EAAYC,EAAMC,EAAM5B,EAAKI,iBACpCgB,EAAS,EAETS,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB9B,EAAKI,eAC3C8B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOf,CACP,CASD,SAASgB,EAAa3B,GACrB,IAAI4B,EACA1B,EAMJ,OAHAA,EAAIiB,EAAMnB,IAGDD,EAAKiB,QAAUjB,EAAMG,GAAIc,OAC1BjB,EAAMG,GAAI2B,MAGblB,EAAOX,EAAIT,EAAKI,cACb,MAERiC,EAAM,IAAIE,EAAa9B,GAGvBW,GAAUX,EAEH4B,EACP,CAWD,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,EACzB,CAkBD,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAxB,EACAP,EACAqC,EACAC,EACAN,EACA/B,EAUJ,GALCgC,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAO3B,EAAO6B,IAEb,MAAM,IAAIrC,UAAWC,EAAQ,QAASoC,IAEvC,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKpC,EAAsBmB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAzB,EAAMO,UAAW,IACPC,OACL0B,EAAmBlC,GACvBA,EAAMmC,EAAgBnC,EAAK,GAChBoC,EAAkBpC,GAC7BA,EAAMqC,EAAerC,EAAK,GACf,WAAWsC,KAAMZ,KAE5BD,GAAO,GAGK,QADbhC,EAAM8B,EAAYC,EAAMC,EAAKC,IAE5B,OAAOjC,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAIqC,IAAK9B,GACFP,EAKR,IAFAsC,EAAMQ,EAAkBvC,GAAMwC,OAC9BV,EAAMS,EAAkB9C,GAAMgD,OACxB/C,EAAI,EAAGA,EAAI+B,EAAK/B,IACrBoC,EAAKrC,EAAKC,EAAGqC,EAAK/B,EAAKN,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,QAASiB,UAAW,IACjD,CAgBD,SAASO,IACR,IAAIe,EACApC,EACAiD,EACAhD,EAUJ,GAAa,QANZD,EADc,KADfoC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCmC,EADIzC,EAAiBR,GACf0C,EAAgB1C,EAAK,GAChBM,EAAgBN,GACrB4C,EAAe5C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAIgD,EAAIlC,OAAQd,IAC5BgD,EAAKhD,GAAM,EAGb,OAAOD,CACP,CAcD,SAASsB,EAAMK,GACd,IAAI5B,EACAmD,EACAjD,EACJ,GAAKkD,EAAkBxB,IAASA,EAAIyB,OACnCzB,EAAMA,EAAIyB,YACJ,IAAMC,EAAe1B,GAC3B,MAAM,IAAI/B,UAAWC,EAAQ,4EAA6E8B,IAE3G,GAAKA,EAAI2B,WAAa,EAAI,CAQzB,IAPAvD,EAAIwD,EAAOrC,EAAMS,EAAI2B,aAGrBvD,EAAIyD,EAAK1D,EAAKiB,OAAO,EAAGhB,GAGxBmD,EAAIpD,EAAMC,GACJE,EAAI,EAAGA,EAAIiD,EAAEnC,OAAQd,IAC1B,GAAKiD,EAAGjD,KAAQ0B,EACf,OAAO,EAITuB,EAAEhD,KAAMyB,EACR,CACD,OAAO,CACP,CAOD,SAASJ,IACR,IAAItB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKiB,OAAQd,IAC7BH,EAAMG,GAAIc,OAAS,EAEpBL,EAAS,CACT,CACF,CCnTG,IAAC+C,EAAiBhD,ICPrBU,EAAAuC,EAAA,UAAAjD"} \ No newline at end of file diff --git a/lib/bytes_per_element.json b/lib/bytes_per_element.json deleted file mode 100644 index f97fe70..0000000 --- a/lib/bytes_per_element.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "float64": 8, - "float32": 4, - "int16": 2, - "int32": 4, - "int8": 1, - "uint16": 2, - "uint32": 4, - "uint8": 1, - "uint8c": 1, - "complex64": 8, - "complex128": 16 -} diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index c71c8f2..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "highWaterMark": 9007199254740992 -} diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index b75e403..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,370 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var isComplex64Array = require( '@stdlib/assert-is-complex64array' ); -var isComplex128Array = require( '@stdlib/assert-is-complex128array' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var ctors = require( '@stdlib/array-typed-ctors' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( '@stdlib/utils-copy' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil = require( '@stdlib/math-base-special-ceil' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); -var log2 = require( '@stdlib/math-base-special-log2' ); -var min = require( '@stdlib/math-base-special-min' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); -var createPool = require( './pool.js' ); -var BYTES_PER_ELEMENT = require( './bytes_per_element.json' ); - - -// VARIABLES // - -var Complex64Array = ctors( 'complex64' ); -var Complex128Array = ctors( 'complex128' ); - - -// FUNCTIONS // - -/** -* Tests whether an array is a single-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a single-precision complex floating-point number array -*/ -function isCmplx64Array( arr ) { - return ( arr instanceof Complex64Array ); -} - -/** -* Tests whether an array is a double-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a double-precision complex floating-point number array -*/ -function isCmplx128Array( arr ) { - return ( arr instanceof Complex128Array ); -} - - -// MAIN // - -/** -* Creates a typed array pool. -* -* @param {Options} [options] - pool options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} allocator -* -* @example -* var typedarraypool = factory(); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -function factory( options ) { - var nbytes; - var pool; - var opts; - var err; - - opts = copy( defaults ); - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - pool = createPool( ceil( log2( opts.highWaterMark ) ) ); - nbytes = 0; - - setReadOnly( malloc, 'malloc', malloc ); // circular reference - setReadOnly( malloc, 'calloc', calloc ); - setReadOnly( malloc, 'free', free ); - setReadOnly( malloc, 'clear', clear ); - setReadOnly( malloc, 'highWaterMark', opts.highWaterMark ); - setReadOnlyAccessor( malloc, 'nbytes', getBytes ); - - return malloc; - - /** - * Returns the number of allocated bytes. - * - * @private - * @returns {NonNegativeInteger} number of allocated bytes - */ - function getBytes() { - return nbytes; - } - - /** - * Returns an array buffer. - * - * @private - * @param {NonNegativeInteger} n - number of bytes - * @returns {(ArrayBuffer|null)} array buffer or null - */ - function arraybuffer( n ) { - var buf; - var i; - - // Convert the number of bytes to an index in our pool table: - i = log2( n ); - - // If we already have an available array buffer, use it... - if ( i < pool.length && pool[ i ].length ) { - return pool[ i ].pop(); - } - // Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate... - if ( nbytes+n > opts.highWaterMark ) { - return null; - } - buf = new ArrayBuffer( n ); - - // Update the running counter of allocated bytes: - nbytes += n; - - return buf; - } - - /** - * Returns a typed array. - * - * @private - * @param {Function} ctor - typed array constructor - * @param {NonNegativeInteger} len - view length - * @param {string} dtype - data type - * @returns {(TypedArray|null)} typed array or null - */ - function typedarray( ctor, len, dtype ) { - var buf; - if ( len === 0 ) { - return new ctor( 0 ); - } - buf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] ); - if ( buf === null ) { - return buf; - } - return new ctor( buf, 0, len ); - } - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length or an array-like object - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function malloc() { - var nargs; - var dtype; - var ctor; - var arr; - var out; - var set; - var get; - var len; - var i; - - nargs = arguments.length; - if ( nargs && isString( arguments[ nargs-1 ] ) ) { - nargs -= 1; - dtype = arguments[ nargs ]; - } else { - dtype = 'float64'; - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( '00d2k', dtype ) ); - } - if ( nargs <= 0 ) { - return new ctor( 0 ); - } - // Check if provided a typed array length... - if ( isNonNegativeInteger( arguments[ 0 ] ) ) { - return typedarray( ctor, arguments[ 0 ], dtype ); - } - // Check if provided an array-like object containing data elements... - if ( isCollection( arguments[ 0 ] ) ) { - arr = arguments[ 0 ]; - len = arr.length; - if ( isComplex128Array( arr ) ) { - arr = reinterpret128( arr, 0 ); - } else if ( isComplex64Array( arr ) ) { - arr = reinterpret64( arr, 0 ); - } else if ( /^complex/.test( dtype ) ) { - // Assume we've been provided an array of interleaved real and imaginary components... - len /= 2; - } - out = typedarray( ctor, len, dtype ); - if ( out === null ) { - return out; - } - if ( isCmplx128Array( out ) || isCmplx64Array( out ) ) { - out.set( arr ); - return out; - } - // Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other "unsafe" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring user's don't do ill-advised things... - get = arraylike2object( arr ).getter; - set = arraylike2object( out ).setter; - for ( i = 0; i < len; i++ ) { - set( out, i, get( arr, i ) ); - } - return out; - } - throw new TypeError( format( '00d33', arguments[ 0 ] ) ); - } - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {NonNegativeInteger} [len=0] - array length - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function calloc() { - var nargs; - var out; - var tmp; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - out = malloc(); - } else if ( nargs === 1 ) { - out = malloc( arguments[ 0 ] ); - } else { - out = malloc( arguments[ 0 ], arguments[ 1 ] ); - } - if ( out !== null ) { - // Initialize the memory... - if ( isCmplx128Array( out ) ) { - tmp = reinterpret128( out, 0 ); - } else if ( isCmplx64Array( out ) ) { - tmp = reinterpret64( out, 0 ); - } else { - tmp = out; - } - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = 0.0; - } - } - return out; - } - - /** - * Frees a typed array or typed array buffer. - * - * ## Notes - * - * - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., "freeing" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool. - * - * @private - * @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free - * @throws {TypeError} must provide a typed array or typed array buffer - * @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed - */ - function free( buf ) { - var n; - var p; - var i; - if ( isTypedArrayLike( buf ) && buf.buffer ) { - buf = buf.buffer; - } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) ); - } - if ( buf.byteLength > 0 ) { - n = floor( log2( buf.byteLength ) ); - - // Prohibit "freeing" array buffers which would potentially allow users to circumvent high water mark limits: - n = min( pool.length-1, n ); - - // Ensure that we do not attempt to free the same buffer more than once... - p = pool[ n ]; - for ( i = 0; i < p.length; i++ ) { - if ( p[ i ] === buf ) { - return false; - } - } - // Add the buffer to our pool of free buffers: - p.push( buf ); - } - return true; - } - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @private - */ - function clear() { - var i; - for ( i = 0; i < pool.length; i++ ) { - pool[ i ].length = 0; - } - nbytes = 0; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6c12a4e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Typed array pool. -* -* @module @stdlib/array-pool -* -* @example -* var typedarraypool = require( '@stdlib/array-pool' ); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8f69ee3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,63 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @name typedarraypool -* @type {Function} -* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a valid array length or an array-like object -* @throws {TypeError} must provide a recognized data type -* @returns {(TypedArray|null)} typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -var typedarraypool = factory(); - - -// EXPORTS // - -module.exports = typedarraypool; diff --git a/lib/pool.js b/lib/pool.js deleted file mode 100644 index 5abd287..0000000 --- a/lib/pool.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Initializes a cache for pooled typed array buffers. -* -* @private -* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size -* @returns {ArrayArray} initialized cache -*/ -function pool( n ) { - var out; - var i; - - out = []; - for ( i = 0; i < n+1; i++ ) { - out.push( [] ); - } - return out; -} - - -// EXPORTS // - -module.exports = pool; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 4135ec9..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'highWaterMark': 1024 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '00d2h', options ) ); - } - if ( hasOwnProp( options, 'highWaterMark' ) ) { - opts.highWaterMark = options.highWaterMark; - if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( '00d35', 'highWaterMark', opts.highWaterMark ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 558fca7..42614cf 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Typed array pool.", "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,76 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.0.x", - "@stdlib/array-buffer": "^0.0.x", - "@stdlib/array-typed-ctors": "^0.0.x", - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-arraybuffer": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-complex128array": "^0.0.x", - "@stdlib/assert-is-complex64array": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/assert-is-typed-array-like": "^0.0.x", - "@stdlib/math-base-special-ceil": "^0.0.x", - "@stdlib/math-base-special-ceil2": "^0.0.x", - "@stdlib/math-base-special-floor": "^0.0.x", - "@stdlib/math-base-special-log2": "^0.0.x", - "@stdlib/math-base-special-min": "^0.0.x", - "@stdlib/strided-base-reinterpret-complex128": "^0.0.x", - "@stdlib/strided-base-reinterpret-complex64": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-copy": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.0.x", - "@stdlib/array-complex64": "^0.0.x", - "@stdlib/array-float32": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/array-int16": "^0.0.x", - "@stdlib/array-int32": "^0.0.x", - "@stdlib/array-int8": "^0.0.x", - "@stdlib/array-uint16": "^0.0.x", - "@stdlib/array-uint32": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/array-uint8c": "^0.0.x", - "@stdlib/assert-instance-of": "^0.0.x", - "@stdlib/assert-is-complex-typed-array": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-typed-array": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/complex-float32": "^0.0.x", - "@stdlib/complex-float64": "^0.0.x", - "@stdlib/complex-imag": "^0.0.x", - "@stdlib/complex-imagf": "^0.0.x", - "@stdlib/complex-real": "^0.0.x", - "@stdlib/complex-realf": "^0.0.x", - "@stdlib/math-base-special-pow": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..77db660 --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 396aee2..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,2240 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function (no options)', function test( t ) { - t.strictEqual( typeof factory(), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - t.strictEqual( typeof factory( {} ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided a `highWaterMark` option which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (length)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a function which returns a typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, length)', function test( t ) { - var typedarraypool = factory(); - var arr; - - arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a `malloc` method which is a circular reference', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - var buf; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the returned function is a property which returns the pool\'s high water mark', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function supports specifying a high water mark which limits the total amount of memory a pool can allocate', function test( t ) { - var typedarraypool; - var arr1; - var arr2; - - typedarraypool = factory({ - 'highWaterMark': 64 // bytes - }); - - typedarraypool.clear(); - - arr1 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr1.length, 8, 'returns expected value' ); - t.strictEqual( arr1.byteLength, 64, 'returns expected value' ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - typedarraypool.free( arr1 ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Create an array which is less than or equal to the high water mark: - arr2 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr2.length, 8, 'returns expected value' ); - t.strictEqual( arr2.byteLength, 64, 'returns expected value' ); - - typedarraypool.free( arr2 ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a property which returns the total number of accumulated bytes', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var typedarraypool; - var arrs; - var i; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 54aa5ee..0000000 --- a/test/test.js +++ /dev/null @@ -1,1797 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var typedarraypool = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -}); From 99645424441b052be429870e2324ea0df308462f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 00:42:58 +0000 Subject: [PATCH 023/103] Transform error messages --- lib/factory.js | 6 +++--- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 2401100..b75e403 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -33,7 +33,7 @@ var ctors = require( '@stdlib/array-typed-ctors' ); var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( '@stdlib/utils-copy' ); var ArrayBuffer = require( '@stdlib/array-buffer' ); var ceil = require( '@stdlib/math-base-special-ceil' ); @@ -226,7 +226,7 @@ function factory( options ) { } ctor = ctors( dtype ); if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '00d2k', dtype ) ); } if ( nargs <= 0 ) { return new ctor( 0 ); @@ -263,7 +263,7 @@ function factory( options ) { } return out; } - throw new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) ); + throw new TypeError( format( '00d33', arguments[ 0 ] ) ); } /** diff --git a/lib/validate.js b/lib/validate.js index ce54890..4135ec9 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '00d2h', options ) ); } if ( hasOwnProp( options, 'highWaterMark' ) ) { opts.highWaterMark = options.highWaterMark; if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) ); + return new TypeError( format( '00d35', 'highWaterMark', opts.highWaterMark ) ); } } return null; diff --git a/package.json b/package.json index 50986ed..558fca7 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "@stdlib/math-base-special-min": "^0.0.x", "@stdlib/strided-base-reinterpret-complex128": "^0.0.x", "@stdlib/strided-base-reinterpret-complex64": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-copy": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", From a9a5a0b5c76298db63b631028f100124585ee527 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 11:46:45 +0000 Subject: [PATCH 024/103] Remove files --- index.d.ts | 359 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4408 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 4500b91..0000000 --- a/index.d.ts +++ /dev/null @@ -1,359 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; -import ArrayBuffer = require( '@stdlib/array-buffer' ); - -/** -* Typed array or null. -*/ -type TypedArrayOrNull = RealOrComplexTypedArray | null; - -/** -* Interface defining pool options. -*/ -interface Options { - /** - * Maximum total memory which can be allocated. - */ - highWaterMark?: number; -} - -/** -* Pool interface. -*/ -interface Pool { - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr = typedarraypool(); - * // returns [] - * - * @example - * var arr = typedarraypool( 'float32' ); - * // returns [] - */ - ( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * // Allocate an array of doubles: - * var arr = typedarraypool( 5, 'float64' ); - * // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * typedarraypool.free( arr ); - * - * @example - * var arr1 = typedarraypool( [ 0.5, 0.5, 0.5 ] ); - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * @example - * var arr1 = [ 0.5, 0.5, 0.5 ]; - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - */ - ( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc(); - * // returns [] - * - * var arr2 = typedarraypool.calloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param length - typed array length - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc( 5 ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * var arr2 = typedarraypool.calloc( 5, 'uint8' ); - * // returns [ 0, 0, 0, 0, 0 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( length: number, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc(); - * // returns [] - * - * var arr2 = typedarraypool.malloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc( 5 ); - * // returns - * - * var arr2 = typedarraypool.malloc( 5, 'uint8' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 5.0, -3.0, 2.0 ] ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr2 = typedarraypool.malloc( arr1 ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr3 = typedarraypool.malloc( arr1, 'int32' ); - * // returns [ 5, -3, 2 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * typedarraypool.free( arr3 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ] ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * var arr2 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ], 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Frees a typed array or typed array buffer for use in a future allocation. - * - * @param buf - typed array or typed array buffer to free - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array for use in a future allocation: - * typedarraypool.free( arr ); - * - * // Create another typed array: - * arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array buffer for use in a future allocation: - * typedarraypool.free( arr.buffer ); - */ - free( buf: RealOrComplexTypedArray | ArrayBuffer ): void; - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr ); - * - * // ... - * - * // Clear all freed buffers: - * typedarraypool.clear(); - */ - clear(): void; - - /** - * Read-only property returning the pool's high water mark. - * - * ## Notes - * - * - Once a high water mark is reached, typed array allocation fails. - * - * @example - * var limit = typedarraypool.highWaterMark; - * // returns - */ - readonly highWaterMark: number; - - /** - * Read-only property returning the total number of allocated bytes. - * - * @example - * var arr = typedarraypool( 5, 'float64' ); - * - * var nbytes = typedarraypool.nbytes; - * // returns - */ - readonly nbytes: number; - - /** - * Creates a typed array pool. - * - * @param options - pool options - * @param options.highWaterMark - maximum total memory which can be allocated - * @throws must provide valid options - * @returns allocator - * - * @example - * var allocator = typedarraypool.factory(); - * - * // Allocate an array of doubles: - * var arr = allocator( 5, 'float64' ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * allocator.free( arr ); - */ - factory( options?: Options ): Pool; -} - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @param arg - an array length or an array-like object -* @param dtype - data type (default: 'float64') -* @returns typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -declare var typedarraypool: Pool; - - -// EXPORTS // - -export = typedarraypool; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 55d247f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";var w={highWaterMark:9007199254740992};function M(e,t){return y(t)?k(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(f("00d35","highWaterMark",e.highWaterMark)):null:new TypeError(f("00d2h",t))}function W(e){var t,r;for(t=[],r=0;rL.highWaterMark?null:(t=new c(e),k+=e,t)}function z(e,t,r){var s;return 0===t?new e(0):null===(s=q(b(t)*E[r]))?s:new e(s,0,t)}function C(){var e,i,n,l,j,c,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(n=d(i)))throw new TypeError(f("00d2k",i));if(e<=0)return new n(0);if(r(arguments[0]))return z(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,m(l)?l=h(l,0):o(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=z(n,u,i)))return j;if(B(j)||A(j))return j.set(l),j;for(g=p(l).getter,c=p(j).setter,b=0;b0){for(t=u(v(e.byteLength)),t=x(T.length-1,t),r=T[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = copy( defaults );\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '00d2k', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring user's don't do ill-advised things...\n\t\t\tget = arraylike2object( arr ).getter;\n\t\t\tset = arraylike2object( out ).setter;\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '00d33', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool' ;\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","copy","defaults","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","arraylike2object","getter","setter","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;4pEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,QAAS,gBAAiBP,EAAKI,gBAGxD,KARC,IAAIE,UAAWC,EAAQ,QAASN,GASzC,CC/BA,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,iHCaIG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EAAOsB,EAAMC,GACRC,UAAUC,SACdJ,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOkB,EAAYC,EAAMC,EAAM5B,EAAKI,iBACpCgB,EAAS,EAETS,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB9B,EAAKI,eAC3C8B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOf,CACP,CASD,SAASgB,EAAa3B,GACrB,IAAI4B,EACA1B,EAMJ,OAHAA,EAAIiB,EAAMnB,IAGDD,EAAKiB,QAAUjB,EAAMG,GAAIc,OAC1BjB,EAAMG,GAAI2B,MAGblB,EAAOX,EAAIT,EAAKI,cACb,MAERiC,EAAM,IAAIE,EAAa9B,GAGvBW,GAAUX,EAEH4B,EACP,CAWD,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,EACzB,CAkBD,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAxB,EACAP,EACAqC,EACAC,EACAN,EACA/B,EAUJ,GALCgC,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAO3B,EAAO6B,IAEb,MAAM,IAAIrC,UAAWC,EAAQ,QAASoC,IAEvC,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKpC,EAAsBmB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAzB,EAAMO,UAAW,IACPC,OACL0B,EAAmBlC,GACvBA,EAAMmC,EAAgBnC,EAAK,GAChBoC,EAAkBpC,GAC7BA,EAAMqC,EAAerC,EAAK,GACf,WAAWsC,KAAMZ,KAE5BD,GAAO,GAGK,QADbhC,EAAM8B,EAAYC,EAAMC,EAAKC,IAE5B,OAAOjC,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAIqC,IAAK9B,GACFP,EAKR,IAFAsC,EAAMQ,EAAkBvC,GAAMwC,OAC9BV,EAAMS,EAAkB9C,GAAMgD,OACxB/C,EAAI,EAAGA,EAAI+B,EAAK/B,IACrBoC,EAAKrC,EAAKC,EAAGqC,EAAK/B,EAAKN,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,QAASiB,UAAW,IACjD,CAgBD,SAASO,IACR,IAAIe,EACApC,EACAiD,EACAhD,EAUJ,GAAa,QANZD,EADc,KADfoC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCmC,EADIzC,EAAiBR,GACf0C,EAAgB1C,EAAK,GAChBM,EAAgBN,GACrB4C,EAAe5C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAIgD,EAAIlC,OAAQd,IAC5BgD,EAAKhD,GAAM,EAGb,OAAOD,CACP,CAcD,SAASsB,EAAMK,GACd,IAAI5B,EACAmD,EACAjD,EACJ,GAAKkD,EAAkBxB,IAASA,EAAIyB,OACnCzB,EAAMA,EAAIyB,YACJ,IAAMC,EAAe1B,GAC3B,MAAM,IAAI/B,UAAWC,EAAQ,4EAA6E8B,IAE3G,GAAKA,EAAI2B,WAAa,EAAI,CAQzB,IAPAvD,EAAIwD,EAAOrC,EAAMS,EAAI2B,aAGrBvD,EAAIyD,EAAK1D,EAAKiB,OAAO,EAAGhB,GAGxBmD,EAAIpD,EAAMC,GACJE,EAAI,EAAGA,EAAIiD,EAAEnC,OAAQd,IAC1B,GAAKiD,EAAGjD,KAAQ0B,EACf,OAAO,EAITuB,EAAEhD,KAAMyB,EACR,CACD,OAAO,CACP,CAOD,SAASJ,IACR,IAAItB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKiB,OAAQd,IAC7BH,EAAMG,GAAIc,OAAS,EAEpBL,EAAS,CACT,CACF,CCnTG,IAAC+C,EAAiBhD,ICPrBU,EAAAuC,EAAA,UAAAjD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 77db660..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 674c31adc632efbaa78114068cf2ab24ff6b20ea Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 11:47:44 +0000 Subject: [PATCH 025/103] 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 | 43 +- benchmark/benchmark.calloc.js | 246 -- benchmark/benchmark.factory.js | 71 - benchmark/benchmark.js | 246 -- benchmark/benchmark.length.complex128.js | 102 - benchmark/benchmark.length.complex64.js | 102 - benchmark/benchmark.length.float32.js | 102 - benchmark/benchmark.length.float64.js | 102 - benchmark/benchmark.length.int16.js | 102 - benchmark/benchmark.length.int32.js | 102 - benchmark/benchmark.length.int8.js | 102 - benchmark/benchmark.length.uint16.js | 102 - benchmark/benchmark.length.uint32.js | 102 - benchmark/benchmark.length.uint8.js | 102 - benchmark/benchmark.length.uint8c.js | 102 - benchmark/benchmark.malloc.js | 246 -- branches.md | 53 - docs/repl.txt | 347 -- docs/types/test.ts | 193 - examples/index.js | 80 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/bytes_per_element.json | 13 - lib/defaults.json | 3 - lib/factory.js | 370 -- lib/index.js | 56 - lib/main.js | 63 - lib/pool.js | 44 - lib/validate.js | 66 - package.json | 97 +- stats.html | 4044 +++++++++++++++++++++ test/test.factory.js | 2240 ------------ test/test.js | 1797 --------- 57 files changed, 4073 insertions(+), 10299 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.calloc.js delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.complex128.js delete mode 100644 benchmark/benchmark.length.complex64.js delete mode 100644 benchmark/benchmark.length.float32.js delete mode 100644 benchmark/benchmark.length.float64.js delete mode 100644 benchmark/benchmark.length.int16.js delete mode 100644 benchmark/benchmark.length.int32.js delete mode 100644 benchmark/benchmark.length.int8.js delete mode 100644 benchmark/benchmark.length.uint16.js delete mode 100644 benchmark/benchmark.length.uint32.js delete mode 100644 benchmark/benchmark.length.uint8.js delete mode 100644 benchmark/benchmark.length.uint8c.js delete mode 100644 benchmark/benchmark.malloc.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/bytes_per_element.json delete mode 100644 lib/defaults.json delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/pool.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 4b28eac..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-03T23:01:11.646Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ea35f20..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/array/pool) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 fc6d38a..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/array/pool) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 9ef1395..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 37ddb4f..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,781 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -482,7 +481,7 @@ console.log( 'nbytes: %d', typedarray.nbytes ); ## 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]. @@ -548,7 +547,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm diff --git a/benchmark/benchmark.calloc.js b/benchmark/benchmark.calloc.js deleted file mode 100644 index e5a1c77..0000000 --- a/benchmark/benchmark.calloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':calloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index f7cd676..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = typedarray.factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:highWaterMark', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'highWaterMark': 0 - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.highWaterMark = i; - f = typedarray.factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a023d2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.complex128.js b/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 47b623b..0000000 --- a/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex64.js b/benchmark/benchmark.length.complex64.js deleted file mode 100644 index 40a412b..0000000 --- a/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float32.js b/benchmark/benchmark.length.float32.js deleted file mode 100644 index 0227ed7..0000000 --- a/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float64.js b/benchmark/benchmark.length.float64.js deleted file mode 100644 index 2dbac1c..0000000 --- a/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int16.js b/benchmark/benchmark.length.int16.js deleted file mode 100644 index e2a8adc..0000000 --- a/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int32.js b/benchmark/benchmark.length.int32.js deleted file mode 100644 index e4df0aa..0000000 --- a/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int8.js b/benchmark/benchmark.length.int8.js deleted file mode 100644 index 7ceac11..0000000 --- a/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint16.js b/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 9a532b6..0000000 --- a/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint32.js b/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 98f2d7f..0000000 --- a/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8.js b/benchmark/benchmark.length.uint8.js deleted file mode 100644 index 8359249..0000000 --- a/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8c.js b/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index d47d023..0000000 --- a/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.malloc.js b/benchmark/benchmark.malloc.js deleted file mode 100644 index d4eea72..0000000 --- a/benchmark/benchmark.malloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':malloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 8fce14f..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/array/pool" -click B href "https://github.com/stdlib-js/array-pool/tree/main" -click C href "https://github.com/stdlib-js/array-pool/tree/production" -click D href "https://github.com/stdlib-js/array-pool/tree/esm" -click E href "https://github.com/stdlib-js/array-pool/tree/deno" -click F href "https://github.com/stdlib-js/array-pool/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/pool -[production-url]: https://github.com/stdlib-js/array-pool/tree/production -[deno-url]: https://github.com/stdlib-js/array-pool/tree/deno -[umd-url]: https://github.com/stdlib-js/array-pool/tree/umd -[esm-url]: https://github.com/stdlib-js/array-pool/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5244595..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,347 +0,0 @@ - -{{alias}}( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - Memory is **uninitialized**, which means that the contents of a returned - typed array may contain sensitive contents. - - The function supports the following data types: - - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - The default typed array data type is `float64`. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}() - [] - > arr = {{alias}}( 'float32' ) - [] - - -{{alias}}( length[, dtype] ) - Returns an uninitialized typed array having a specified length from a typed - array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > arr = {{alias}}( 5, 'int32' ) - - - -{{alias}}( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - This method shares the same security vulnerabilities mentioned above. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc() - - > arr = {{alias}}.malloc( 'float32' ) - - - -{{alias}}.malloc( length[, dtype] ) - Returns a typed array having a specified length from a typed array memory - pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc( 5 ) - - > arr = {{alias}}.malloc( 5, 'int32' ) - - - -{{alias}}.malloc( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}.malloc( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.calloc( [dtype] ) - Returns a zero-initialized typed array from a typed array memory pool. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc() - [] - > arr = {{alias}}.calloc( 'float32' ) - [] - - -{{alias}}.calloc( length[, dtype] ) - Returns a zero-initialized typed array having a specified length from a - typed array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}.calloc( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}.free( buf ) - Frees a typed array or typed array buffer for use in a future allocation. - - Parameters - ---------- - buf: TypedArray|ArrayBuffer - Typed array or typed array buffer to free. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ) - - -{{alias}}.clear() - Clears the typed array pool allowing garbage collection of previously - allocated (and currently free) array buffers. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - > {{alias}}.clear() - - -{{alias}}.highWaterMark - Read-only property returning the pool's high water mark. - - Once a high water mark is reached, typed array allocation fails. - - Examples - -------- - > {{alias}}.highWaterMark - - -{{alias}}.nbytes - Read-only property returning the total number of allocated bytes. - - The returned value is the total accumulated value. Hence, anytime a pool - must allocate a new array buffer (i.e., more memory), the pool increments - this value. - - The only time this value is decremented is when a pool is cleared. - - This behavior means that, while allocated buffers which are never freed may, - in fact, be garbage collected, they continue to count against the high water - mark limit. - - Accordingly, you should *always* free allocated buffers in order to prevent - the pool from believing that non-freed buffers are continually in use. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.nbytes - - -{{alias}}.factory( [options] ) - Creates a typed array pool. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.highWaterMark: integer (optional) - Maximum total memory (in bytes) which can be allocated. - - Returns - ------- - fcn: Function - Function for creating typed arrays from a typed array memory pool. - - Examples - -------- - > var pool = {{alias}}.factory(); - > var arr1 = pool( 3, 'float64' ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1014bba..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,193 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-empty */ -/* tslint:disable:no-unused-expression */ - -import typedarraypool = require( './index' ); - - -// TESTS // - -// The function returns a typed array or null... -{ - typedarraypool(); // $ExpectType TypedArrayOrNull - typedarraypool( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the function is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool( true ); // $ExpectError - typedarraypool( false ); // $ExpectError - typedarraypool( null ); // $ExpectError - typedarraypool( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized data type... -{ - typedarraypool( 4, true ); // $ExpectError - typedarraypool( 4, false ); // $ExpectError - typedarraypool( 4, null ); // $ExpectError - typedarraypool( 4, 'abc' ); // $ExpectError - typedarraypool( 4, 123 ); // $ExpectError - typedarraypool( 4, [] ); // $ExpectError - typedarraypool( 4, {} ); // $ExpectError - typedarraypool( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an incorrect number of arguments... -{ - typedarraypool( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `malloc` method which returns a typed array or null... -{ - typedarraypool.malloc(); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.malloc( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `malloc` method is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool.malloc( true ); // $ExpectError - typedarraypool.malloc( false ); // $ExpectError - typedarraypool.malloc( null ); // $ExpectError - typedarraypool.malloc( {} ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.malloc( 4, true ); // $ExpectError - typedarraypool.malloc( 4, false ); // $ExpectError - typedarraypool.malloc( 4, null ); // $ExpectError - typedarraypool.malloc( 4, 'abc' ); // $ExpectError - typedarraypool.malloc( 4, 123 ); // $ExpectError - typedarraypool.malloc( 4, [] ); // $ExpectError - typedarraypool.malloc( 4, {} ); // $ExpectError - typedarraypool.malloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided an incorrect number of arguments... -{ - typedarraypool.malloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `calloc` method which returns a typed array or null... -{ - typedarraypool.calloc(); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `calloc` method is provided a first argument which is not a number... -{ - typedarraypool.calloc( 'abc' ); // $ExpectError - typedarraypool.calloc( true ); // $ExpectError - typedarraypool.calloc( false ); // $ExpectError - typedarraypool.calloc( null ); // $ExpectError - typedarraypool.calloc( {} ); // $ExpectError - typedarraypool.calloc( [] ); // $ExpectError - typedarraypool.calloc( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.calloc( 4, true ); // $ExpectError - typedarraypool.calloc( 4, false ); // $ExpectError - typedarraypool.calloc( 4, null ); // $ExpectError - typedarraypool.calloc( 4, 'abc' ); // $ExpectError - typedarraypool.calloc( 4, 123 ); // $ExpectError - typedarraypool.calloc( 4, [] ); // $ExpectError - typedarraypool.calloc( 4, {} ); // $ExpectError - typedarraypool.calloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided an incorrect number of arguments... -{ - typedarraypool.calloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `factory` method which returns a typed array pool.. -{ - typedarraypool.factory(); // $ExpectType Pool - typedarraypool.factory( { 'highWaterMark': 556 } ); // $ExpectType Pool -} - -// The compiler throws an error if the `factory` method is provided a `highWaterMark` option which is not a number... -{ - typedarraypool.factory( { 'highWaterMark': true } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': false } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': 'abc' } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': null } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': [] } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': {} } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an incorrect number of arguments... -{ - typedarraypool.factory( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` method which returns void... -{ - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.free( arr ); // $ExpectType void -} - -// The compiler throws an error if the `free` method is provided a first argument which is neither a typed array nor array buffer... -{ - typedarraypool.free( true ); // $ExpectError - typedarraypool.free( false ); // $ExpectError - typedarraypool.free( 123 ); // $ExpectError - typedarraypool.free( 'abc' ); // $ExpectError - typedarraypool.free( null ); // $ExpectError - typedarraypool.free( {} ); // $ExpectError - typedarraypool.free( ( x: number ): number => x ); // $ExpectError -} - -// Attached to the main export is a `clear` method which returns void... -{ - typedarraypool.clear(); // $ExpectType void -} - -// The compiler throws an error if the `clear` method is provided arguments... -{ - typedarraypool.clear( {} ); // $ExpectError - typedarraypool.clear( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `highWaterMark` property... -{ - typedarraypool.highWaterMark; // $ExpectType number -} - -// Attached to the main export is a `nbytes` property... -{ - typedarraypool.nbytes; // $ExpectType number -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 24a7846..0000000 --- a/examples/index.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 randu = require( '@stdlib/random-base-randu' ); -var typedarraypool = require( './../lib' ); - -// Create a typed array pool which can allocate at most 1GB: -var typedarray = typedarraypool.factory({ - 'highWaterMark': 1e9 -}); - -// Inspect the pool: -console.log( 'Max bytes: %d', typedarray.highWaterMark ); -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Allocate an array for storing double-precision floating-point numbers: -var arr1 = typedarray( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Fill the array... -var i; -for ( i = 0; i < arr1.length; i++ ) { - arr1[ i ] = randu(); -} - -// Inspect array contents: -console.log( arr1 ); - -// Free the array: -typedarray.free( arr1 ); - -// Allocate another array similar to the previous one: -var arr2 = typedarray( 5, 'float64' ); -// returns - -// Check that we have been returned a new typed array view: -console.log( arr2 === arr1 ); -// => false - -// Inspect array contents: -console.log( arr2 ); - -// Free the array: -typedarray.free( arr2 ); - -// Allocate an initialized array: -var arr3 = typedarray.calloc( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect array contents: -console.log( arr3 ); - -// Free the array: -typedarray.free( arr3 ); - -// Clear the pool: -typedarray.clear(); - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 239fcdc..4500b91 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; import ArrayBuffer = require( '@stdlib/array-buffer' ); diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..55d247f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";var w={highWaterMark:9007199254740992};function M(e,t){return y(t)?k(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(f("00d35","highWaterMark",e.highWaterMark)):null:new TypeError(f("00d2h",t))}function W(e){var t,r;for(t=[],r=0;rL.highWaterMark?null:(t=new c(e),k+=e,t)}function z(e,t,r){var s;return 0===t?new e(0):null===(s=q(b(t)*E[r]))?s:new e(s,0,t)}function C(){var e,i,n,l,j,c,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(n=d(i)))throw new TypeError(f("00d2k",i));if(e<=0)return new n(0);if(r(arguments[0]))return z(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,m(l)?l=h(l,0):o(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=z(n,u,i)))return j;if(B(j)||A(j))return j.set(l),j;for(g=p(l).getter,c=p(j).setter,b=0;b0){for(t=u(v(e.byteLength)),t=x(T.length-1,t),r=T[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = copy( defaults );\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '00d2k', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring user's don't do ill-advised things...\n\t\t\tget = arraylike2object( arr ).getter;\n\t\t\tset = arraylike2object( out ).setter;\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '00d33', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool' ;\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","copy","defaults","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","arraylike2object","getter","setter","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;4pEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,QAAS,gBAAiBP,EAAKI,gBAGxD,KARC,IAAIE,UAAWC,EAAQ,QAASN,GASzC,CC/BA,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,iHCaIG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EAAOsB,EAAMC,GACRC,UAAUC,SACdJ,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOkB,EAAYC,EAAMC,EAAM5B,EAAKI,iBACpCgB,EAAS,EAETS,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB9B,EAAKI,eAC3C8B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOf,CACP,CASD,SAASgB,EAAa3B,GACrB,IAAI4B,EACA1B,EAMJ,OAHAA,EAAIiB,EAAMnB,IAGDD,EAAKiB,QAAUjB,EAAMG,GAAIc,OAC1BjB,EAAMG,GAAI2B,MAGblB,EAAOX,EAAIT,EAAKI,cACb,MAERiC,EAAM,IAAIE,EAAa9B,GAGvBW,GAAUX,EAEH4B,EACP,CAWD,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,EACzB,CAkBD,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAxB,EACAP,EACAqC,EACAC,EACAN,EACA/B,EAUJ,GALCgC,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAO3B,EAAO6B,IAEb,MAAM,IAAIrC,UAAWC,EAAQ,QAASoC,IAEvC,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKpC,EAAsBmB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAzB,EAAMO,UAAW,IACPC,OACL0B,EAAmBlC,GACvBA,EAAMmC,EAAgBnC,EAAK,GAChBoC,EAAkBpC,GAC7BA,EAAMqC,EAAerC,EAAK,GACf,WAAWsC,KAAMZ,KAE5BD,GAAO,GAGK,QADbhC,EAAM8B,EAAYC,EAAMC,EAAKC,IAE5B,OAAOjC,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAIqC,IAAK9B,GACFP,EAKR,IAFAsC,EAAMQ,EAAkBvC,GAAMwC,OAC9BV,EAAMS,EAAkB9C,GAAMgD,OACxB/C,EAAI,EAAGA,EAAI+B,EAAK/B,IACrBoC,EAAKrC,EAAKC,EAAGqC,EAAK/B,EAAKN,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,QAASiB,UAAW,IACjD,CAgBD,SAASO,IACR,IAAIe,EACApC,EACAiD,EACAhD,EAUJ,GAAa,QANZD,EADc,KADfoC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCmC,EADIzC,EAAiBR,GACf0C,EAAgB1C,EAAK,GAChBM,EAAgBN,GACrB4C,EAAe5C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAIgD,EAAIlC,OAAQd,IAC5BgD,EAAKhD,GAAM,EAGb,OAAOD,CACP,CAcD,SAASsB,EAAMK,GACd,IAAI5B,EACAmD,EACAjD,EACJ,GAAKkD,EAAkBxB,IAASA,EAAIyB,OACnCzB,EAAMA,EAAIyB,YACJ,IAAMC,EAAe1B,GAC3B,MAAM,IAAI/B,UAAWC,EAAQ,4EAA6E8B,IAE3G,GAAKA,EAAI2B,WAAa,EAAI,CAQzB,IAPAvD,EAAIwD,EAAOrC,EAAMS,EAAI2B,aAGrBvD,EAAIyD,EAAK1D,EAAKiB,OAAO,EAAGhB,GAGxBmD,EAAIpD,EAAMC,GACJE,EAAI,EAAGA,EAAIiD,EAAEnC,OAAQd,IAC1B,GAAKiD,EAAGjD,KAAQ0B,EACf,OAAO,EAITuB,EAAEhD,KAAMyB,EACR,CACD,OAAO,CACP,CAOD,SAASJ,IACR,IAAItB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKiB,OAAQd,IAC7BH,EAAMG,GAAIc,OAAS,EAEpBL,EAAS,CACT,CACF,CCnTG,IAAC+C,EAAiBhD,ICPrBU,EAAAuC,EAAA,UAAAjD"} \ No newline at end of file diff --git a/lib/bytes_per_element.json b/lib/bytes_per_element.json deleted file mode 100644 index f97fe70..0000000 --- a/lib/bytes_per_element.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "float64": 8, - "float32": 4, - "int16": 2, - "int32": 4, - "int8": 1, - "uint16": 2, - "uint32": 4, - "uint8": 1, - "uint8c": 1, - "complex64": 8, - "complex128": 16 -} diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index c71c8f2..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "highWaterMark": 9007199254740992 -} diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index b75e403..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,370 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var isComplex64Array = require( '@stdlib/assert-is-complex64array' ); -var isComplex128Array = require( '@stdlib/assert-is-complex128array' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var ctors = require( '@stdlib/array-typed-ctors' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( '@stdlib/utils-copy' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil = require( '@stdlib/math-base-special-ceil' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); -var log2 = require( '@stdlib/math-base-special-log2' ); -var min = require( '@stdlib/math-base-special-min' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); -var createPool = require( './pool.js' ); -var BYTES_PER_ELEMENT = require( './bytes_per_element.json' ); - - -// VARIABLES // - -var Complex64Array = ctors( 'complex64' ); -var Complex128Array = ctors( 'complex128' ); - - -// FUNCTIONS // - -/** -* Tests whether an array is a single-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a single-precision complex floating-point number array -*/ -function isCmplx64Array( arr ) { - return ( arr instanceof Complex64Array ); -} - -/** -* Tests whether an array is a double-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a double-precision complex floating-point number array -*/ -function isCmplx128Array( arr ) { - return ( arr instanceof Complex128Array ); -} - - -// MAIN // - -/** -* Creates a typed array pool. -* -* @param {Options} [options] - pool options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} allocator -* -* @example -* var typedarraypool = factory(); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -function factory( options ) { - var nbytes; - var pool; - var opts; - var err; - - opts = copy( defaults ); - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - pool = createPool( ceil( log2( opts.highWaterMark ) ) ); - nbytes = 0; - - setReadOnly( malloc, 'malloc', malloc ); // circular reference - setReadOnly( malloc, 'calloc', calloc ); - setReadOnly( malloc, 'free', free ); - setReadOnly( malloc, 'clear', clear ); - setReadOnly( malloc, 'highWaterMark', opts.highWaterMark ); - setReadOnlyAccessor( malloc, 'nbytes', getBytes ); - - return malloc; - - /** - * Returns the number of allocated bytes. - * - * @private - * @returns {NonNegativeInteger} number of allocated bytes - */ - function getBytes() { - return nbytes; - } - - /** - * Returns an array buffer. - * - * @private - * @param {NonNegativeInteger} n - number of bytes - * @returns {(ArrayBuffer|null)} array buffer or null - */ - function arraybuffer( n ) { - var buf; - var i; - - // Convert the number of bytes to an index in our pool table: - i = log2( n ); - - // If we already have an available array buffer, use it... - if ( i < pool.length && pool[ i ].length ) { - return pool[ i ].pop(); - } - // Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate... - if ( nbytes+n > opts.highWaterMark ) { - return null; - } - buf = new ArrayBuffer( n ); - - // Update the running counter of allocated bytes: - nbytes += n; - - return buf; - } - - /** - * Returns a typed array. - * - * @private - * @param {Function} ctor - typed array constructor - * @param {NonNegativeInteger} len - view length - * @param {string} dtype - data type - * @returns {(TypedArray|null)} typed array or null - */ - function typedarray( ctor, len, dtype ) { - var buf; - if ( len === 0 ) { - return new ctor( 0 ); - } - buf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] ); - if ( buf === null ) { - return buf; - } - return new ctor( buf, 0, len ); - } - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length or an array-like object - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function malloc() { - var nargs; - var dtype; - var ctor; - var arr; - var out; - var set; - var get; - var len; - var i; - - nargs = arguments.length; - if ( nargs && isString( arguments[ nargs-1 ] ) ) { - nargs -= 1; - dtype = arguments[ nargs ]; - } else { - dtype = 'float64'; - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( '00d2k', dtype ) ); - } - if ( nargs <= 0 ) { - return new ctor( 0 ); - } - // Check if provided a typed array length... - if ( isNonNegativeInteger( arguments[ 0 ] ) ) { - return typedarray( ctor, arguments[ 0 ], dtype ); - } - // Check if provided an array-like object containing data elements... - if ( isCollection( arguments[ 0 ] ) ) { - arr = arguments[ 0 ]; - len = arr.length; - if ( isComplex128Array( arr ) ) { - arr = reinterpret128( arr, 0 ); - } else if ( isComplex64Array( arr ) ) { - arr = reinterpret64( arr, 0 ); - } else if ( /^complex/.test( dtype ) ) { - // Assume we've been provided an array of interleaved real and imaginary components... - len /= 2; - } - out = typedarray( ctor, len, dtype ); - if ( out === null ) { - return out; - } - if ( isCmplx128Array( out ) || isCmplx64Array( out ) ) { - out.set( arr ); - return out; - } - // Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other "unsafe" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring user's don't do ill-advised things... - get = arraylike2object( arr ).getter; - set = arraylike2object( out ).setter; - for ( i = 0; i < len; i++ ) { - set( out, i, get( arr, i ) ); - } - return out; - } - throw new TypeError( format( '00d33', arguments[ 0 ] ) ); - } - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {NonNegativeInteger} [len=0] - array length - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function calloc() { - var nargs; - var out; - var tmp; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - out = malloc(); - } else if ( nargs === 1 ) { - out = malloc( arguments[ 0 ] ); - } else { - out = malloc( arguments[ 0 ], arguments[ 1 ] ); - } - if ( out !== null ) { - // Initialize the memory... - if ( isCmplx128Array( out ) ) { - tmp = reinterpret128( out, 0 ); - } else if ( isCmplx64Array( out ) ) { - tmp = reinterpret64( out, 0 ); - } else { - tmp = out; - } - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = 0.0; - } - } - return out; - } - - /** - * Frees a typed array or typed array buffer. - * - * ## Notes - * - * - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., "freeing" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool. - * - * @private - * @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free - * @throws {TypeError} must provide a typed array or typed array buffer - * @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed - */ - function free( buf ) { - var n; - var p; - var i; - if ( isTypedArrayLike( buf ) && buf.buffer ) { - buf = buf.buffer; - } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) ); - } - if ( buf.byteLength > 0 ) { - n = floor( log2( buf.byteLength ) ); - - // Prohibit "freeing" array buffers which would potentially allow users to circumvent high water mark limits: - n = min( pool.length-1, n ); - - // Ensure that we do not attempt to free the same buffer more than once... - p = pool[ n ]; - for ( i = 0; i < p.length; i++ ) { - if ( p[ i ] === buf ) { - return false; - } - } - // Add the buffer to our pool of free buffers: - p.push( buf ); - } - return true; - } - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @private - */ - function clear() { - var i; - for ( i = 0; i < pool.length; i++ ) { - pool[ i ].length = 0; - } - nbytes = 0; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6c12a4e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Typed array pool. -* -* @module @stdlib/array-pool -* -* @example -* var typedarraypool = require( '@stdlib/array-pool' ); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8f69ee3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,63 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @name typedarraypool -* @type {Function} -* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a valid array length or an array-like object -* @throws {TypeError} must provide a recognized data type -* @returns {(TypedArray|null)} typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -var typedarraypool = factory(); - - -// EXPORTS // - -module.exports = typedarraypool; diff --git a/lib/pool.js b/lib/pool.js deleted file mode 100644 index 5abd287..0000000 --- a/lib/pool.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Initializes a cache for pooled typed array buffers. -* -* @private -* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size -* @returns {ArrayArray} initialized cache -*/ -function pool( n ) { - var out; - var i; - - out = []; - for ( i = 0; i < n+1; i++ ) { - out.push( [] ); - } - return out; -} - - -// EXPORTS // - -module.exports = pool; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 4135ec9..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'highWaterMark': 1024 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '00d2h', options ) ); - } - if ( hasOwnProp( options, 'highWaterMark' ) ) { - opts.highWaterMark = options.highWaterMark; - if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( '00d35', 'highWaterMark', opts.highWaterMark ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 558fca7..42614cf 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Typed array pool.", "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,76 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.0.x", - "@stdlib/array-buffer": "^0.0.x", - "@stdlib/array-typed-ctors": "^0.0.x", - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-arraybuffer": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-complex128array": "^0.0.x", - "@stdlib/assert-is-complex64array": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/assert-is-typed-array-like": "^0.0.x", - "@stdlib/math-base-special-ceil": "^0.0.x", - "@stdlib/math-base-special-ceil2": "^0.0.x", - "@stdlib/math-base-special-floor": "^0.0.x", - "@stdlib/math-base-special-log2": "^0.0.x", - "@stdlib/math-base-special-min": "^0.0.x", - "@stdlib/strided-base-reinterpret-complex128": "^0.0.x", - "@stdlib/strided-base-reinterpret-complex64": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-copy": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.0.x", - "@stdlib/array-complex64": "^0.0.x", - "@stdlib/array-float32": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/array-int16": "^0.0.x", - "@stdlib/array-int32": "^0.0.x", - "@stdlib/array-int8": "^0.0.x", - "@stdlib/array-uint16": "^0.0.x", - "@stdlib/array-uint32": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/array-uint8c": "^0.0.x", - "@stdlib/assert-instance-of": "^0.0.x", - "@stdlib/assert-is-complex-typed-array": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-typed-array": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/complex-float32": "^0.0.x", - "@stdlib/complex-float64": "^0.0.x", - "@stdlib/complex-imag": "^0.0.x", - "@stdlib/complex-imagf": "^0.0.x", - "@stdlib/complex-real": "^0.0.x", - "@stdlib/complex-realf": "^0.0.x", - "@stdlib/math-base-special-pow": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..cd6041e --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 396aee2..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,2240 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function (no options)', function test( t ) { - t.strictEqual( typeof factory(), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - t.strictEqual( typeof factory( {} ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided a `highWaterMark` option which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (length)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a function which returns a typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, length)', function test( t ) { - var typedarraypool = factory(); - var arr; - - arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a `malloc` method which is a circular reference', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - var buf; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the returned function is a property which returns the pool\'s high water mark', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function supports specifying a high water mark which limits the total amount of memory a pool can allocate', function test( t ) { - var typedarraypool; - var arr1; - var arr2; - - typedarraypool = factory({ - 'highWaterMark': 64 // bytes - }); - - typedarraypool.clear(); - - arr1 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr1.length, 8, 'returns expected value' ); - t.strictEqual( arr1.byteLength, 64, 'returns expected value' ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - typedarraypool.free( arr1 ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Create an array which is less than or equal to the high water mark: - arr2 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr2.length, 8, 'returns expected value' ); - t.strictEqual( arr2.byteLength, 64, 'returns expected value' ); - - typedarraypool.free( arr2 ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a property which returns the total number of accumulated bytes', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var typedarraypool; - var arrs; - var i; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 54aa5ee..0000000 --- a/test/test.js +++ /dev/null @@ -1,1797 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var typedarraypool = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -}); From ca627816e06ac80dfc37aee6ca93be2c116e0c7b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 04:41:25 +0000 Subject: [PATCH 026/103] Transform error messages --- lib/factory.js | 6 +++--- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 2401100..b75e403 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -33,7 +33,7 @@ var ctors = require( '@stdlib/array-typed-ctors' ); var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var copy = require( '@stdlib/utils-copy' ); var ArrayBuffer = require( '@stdlib/array-buffer' ); var ceil = require( '@stdlib/math-base-special-ceil' ); @@ -226,7 +226,7 @@ function factory( options ) { } ctor = ctors( dtype ); if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '00d2k', dtype ) ); } if ( nargs <= 0 ) { return new ctor( 0 ); @@ -263,7 +263,7 @@ function factory( options ) { } return out; } - throw new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) ); + throw new TypeError( format( '00d33', arguments[ 0 ] ) ); } /** diff --git a/lib/validate.js b/lib/validate.js index ce54890..4135ec9 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '00d2h', options ) ); } if ( hasOwnProp( options, 'highWaterMark' ) ) { opts.highWaterMark = options.highWaterMark; if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) ); + return new TypeError( format( '00d35', 'highWaterMark', opts.highWaterMark ) ); } } return null; diff --git a/package.json b/package.json index 3447fd2..34e736e 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "@stdlib/math-base-special-min": "^0.0.x", "@stdlib/strided-base-reinterpret-complex128": "^0.0.x", "@stdlib/strided-base-reinterpret-complex64": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-copy": "^0.0.x", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", From 4ba0e697451a4f89077671dbb5adabc872034754 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 18:47:53 +0000 Subject: [PATCH 027/103] Remove files --- index.d.ts | 359 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4408 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 4500b91..0000000 --- a/index.d.ts +++ /dev/null @@ -1,359 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; -import ArrayBuffer = require( '@stdlib/array-buffer' ); - -/** -* Typed array or null. -*/ -type TypedArrayOrNull = RealOrComplexTypedArray | null; - -/** -* Interface defining pool options. -*/ -interface Options { - /** - * Maximum total memory which can be allocated. - */ - highWaterMark?: number; -} - -/** -* Pool interface. -*/ -interface Pool { - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr = typedarraypool(); - * // returns [] - * - * @example - * var arr = typedarraypool( 'float32' ); - * // returns [] - */ - ( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * // Allocate an array of doubles: - * var arr = typedarraypool( 5, 'float64' ); - * // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * typedarraypool.free( arr ); - * - * @example - * var arr1 = typedarraypool( [ 0.5, 0.5, 0.5 ] ); - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * @example - * var arr1 = [ 0.5, 0.5, 0.5 ]; - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - */ - ( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc(); - * // returns [] - * - * var arr2 = typedarraypool.calloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param length - typed array length - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc( 5 ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * var arr2 = typedarraypool.calloc( 5, 'uint8' ); - * // returns [ 0, 0, 0, 0, 0 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( length: number, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc(); - * // returns [] - * - * var arr2 = typedarraypool.malloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc( 5 ); - * // returns - * - * var arr2 = typedarraypool.malloc( 5, 'uint8' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 5.0, -3.0, 2.0 ] ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr2 = typedarraypool.malloc( arr1 ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr3 = typedarraypool.malloc( arr1, 'int32' ); - * // returns [ 5, -3, 2 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * typedarraypool.free( arr3 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ] ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * var arr2 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ], 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Frees a typed array or typed array buffer for use in a future allocation. - * - * @param buf - typed array or typed array buffer to free - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array for use in a future allocation: - * typedarraypool.free( arr ); - * - * // Create another typed array: - * arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array buffer for use in a future allocation: - * typedarraypool.free( arr.buffer ); - */ - free( buf: RealOrComplexTypedArray | ArrayBuffer ): void; - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr ); - * - * // ... - * - * // Clear all freed buffers: - * typedarraypool.clear(); - */ - clear(): void; - - /** - * Read-only property returning the pool's high water mark. - * - * ## Notes - * - * - Once a high water mark is reached, typed array allocation fails. - * - * @example - * var limit = typedarraypool.highWaterMark; - * // returns - */ - readonly highWaterMark: number; - - /** - * Read-only property returning the total number of allocated bytes. - * - * @example - * var arr = typedarraypool( 5, 'float64' ); - * - * var nbytes = typedarraypool.nbytes; - * // returns - */ - readonly nbytes: number; - - /** - * Creates a typed array pool. - * - * @param options - pool options - * @param options.highWaterMark - maximum total memory which can be allocated - * @throws must provide valid options - * @returns allocator - * - * @example - * var allocator = typedarraypool.factory(); - * - * // Allocate an array of doubles: - * var arr = allocator( 5, 'float64' ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * allocator.free( arr ); - */ - factory( options?: Options ): Pool; -} - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @param arg - an array length or an array-like object -* @param dtype - data type (default: 'float64') -* @returns typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -declare var typedarraypool: Pool; - - -// EXPORTS // - -export = typedarraypool; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 55d247f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";var w={highWaterMark:9007199254740992};function M(e,t){return y(t)?k(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(f("00d35","highWaterMark",e.highWaterMark)):null:new TypeError(f("00d2h",t))}function W(e){var t,r;for(t=[],r=0;rL.highWaterMark?null:(t=new c(e),k+=e,t)}function z(e,t,r){var s;return 0===t?new e(0):null===(s=q(b(t)*E[r]))?s:new e(s,0,t)}function C(){var e,i,n,l,j,c,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(n=d(i)))throw new TypeError(f("00d2k",i));if(e<=0)return new n(0);if(r(arguments[0]))return z(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,m(l)?l=h(l,0):o(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=z(n,u,i)))return j;if(B(j)||A(j))return j.set(l),j;for(g=p(l).getter,c=p(j).setter,b=0;b0){for(t=u(v(e.byteLength)),t=x(T.length-1,t),r=T[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = copy( defaults );\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '00d2k', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring user's don't do ill-advised things...\n\t\t\tget = arraylike2object( arr ).getter;\n\t\t\tset = arraylike2object( out ).setter;\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '00d33', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool' ;\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property' ;\nimport main from './main.js' ;\nimport factory from './factory.js' ;\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","copy","defaults","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","arraylike2object","getter","setter","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;4pEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,QAAS,gBAAiBP,EAAKI,gBAGxD,KARC,IAAIE,UAAWC,EAAQ,QAASN,GASzC,CC/BA,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,iHCaIG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EAAOsB,EAAMC,GACRC,UAAUC,SACdJ,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOkB,EAAYC,EAAMC,EAAM5B,EAAKI,iBACpCgB,EAAS,EAETS,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB9B,EAAKI,eAC3C8B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOf,CACP,CASD,SAASgB,EAAa3B,GACrB,IAAI4B,EACA1B,EAMJ,OAHAA,EAAIiB,EAAMnB,IAGDD,EAAKiB,QAAUjB,EAAMG,GAAIc,OAC1BjB,EAAMG,GAAI2B,MAGblB,EAAOX,EAAIT,EAAKI,cACb,MAERiC,EAAM,IAAIE,EAAa9B,GAGvBW,GAAUX,EAEH4B,EACP,CAWD,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,EACzB,CAkBD,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAxB,EACAP,EACAqC,EACAC,EACAN,EACA/B,EAUJ,GALCgC,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAO3B,EAAO6B,IAEb,MAAM,IAAIrC,UAAWC,EAAQ,QAASoC,IAEvC,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKpC,EAAsBmB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAzB,EAAMO,UAAW,IACPC,OACL0B,EAAmBlC,GACvBA,EAAMmC,EAAgBnC,EAAK,GAChBoC,EAAkBpC,GAC7BA,EAAMqC,EAAerC,EAAK,GACf,WAAWsC,KAAMZ,KAE5BD,GAAO,GAGK,QADbhC,EAAM8B,EAAYC,EAAMC,EAAKC,IAE5B,OAAOjC,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAIqC,IAAK9B,GACFP,EAKR,IAFAsC,EAAMQ,EAAkBvC,GAAMwC,OAC9BV,EAAMS,EAAkB9C,GAAMgD,OACxB/C,EAAI,EAAGA,EAAI+B,EAAK/B,IACrBoC,EAAKrC,EAAKC,EAAGqC,EAAK/B,EAAKN,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,QAASiB,UAAW,IACjD,CAgBD,SAASO,IACR,IAAIe,EACApC,EACAiD,EACAhD,EAUJ,GAAa,QANZD,EADc,KADfoC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCmC,EADIzC,EAAiBR,GACf0C,EAAgB1C,EAAK,GAChBM,EAAgBN,GACrB4C,EAAe5C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAIgD,EAAIlC,OAAQd,IAC5BgD,EAAKhD,GAAM,EAGb,OAAOD,CACP,CAcD,SAASsB,EAAMK,GACd,IAAI5B,EACAmD,EACAjD,EACJ,GAAKkD,EAAkBxB,IAASA,EAAIyB,OACnCzB,EAAMA,EAAIyB,YACJ,IAAMC,EAAe1B,GAC3B,MAAM,IAAI/B,UAAWC,EAAQ,4EAA6E8B,IAE3G,GAAKA,EAAI2B,WAAa,EAAI,CAQzB,IAPAvD,EAAIwD,EAAOrC,EAAMS,EAAI2B,aAGrBvD,EAAIyD,EAAK1D,EAAKiB,OAAO,EAAGhB,GAGxBmD,EAAIpD,EAAMC,GACJE,EAAI,EAAGA,EAAIiD,EAAEnC,OAAQd,IAC1B,GAAKiD,EAAGjD,KAAQ0B,EACf,OAAO,EAITuB,EAAEhD,KAAMyB,EACR,CACD,OAAO,CACP,CAOD,SAASJ,IACR,IAAItB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKiB,OAAQd,IAC7BH,EAAMG,GAAIc,OAAS,EAEpBL,EAAS,CACT,CACF,CCnTG,IAAC+C,EAAiBhD,ICPrBU,EAAAuC,EAAA,UAAAjD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index cd6041e..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 8b06dd37b6601341874283df9ad712a36d9ecb77 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 18:48:56 +0000 Subject: [PATCH 028/103] 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 | 43 +- benchmark/benchmark.calloc.js | 246 -- benchmark/benchmark.factory.js | 71 - benchmark/benchmark.js | 246 -- benchmark/benchmark.length.complex128.js | 102 - benchmark/benchmark.length.complex64.js | 102 - benchmark/benchmark.length.float32.js | 102 - benchmark/benchmark.length.float64.js | 102 - benchmark/benchmark.length.int16.js | 102 - benchmark/benchmark.length.int32.js | 102 - benchmark/benchmark.length.int8.js | 102 - benchmark/benchmark.length.uint16.js | 102 - benchmark/benchmark.length.uint32.js | 102 - benchmark/benchmark.length.uint8.js | 102 - benchmark/benchmark.length.uint8c.js | 102 - benchmark/benchmark.malloc.js | 246 -- branches.md | 53 - docs/repl.txt | 347 -- docs/types/test.ts | 193 - examples/index.js | 80 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/bytes_per_element.json | 13 - lib/defaults.json | 3 - lib/factory.js | 370 -- lib/index.js | 56 - lib/main.js | 63 - lib/pool.js | 44 - lib/validate.js | 66 - package.json | 97 +- stats.html | 4044 +++++++++++++++++++++ test/test.factory.js | 2240 ------------ test/test.js | 1797 --------- 57 files changed, 4073 insertions(+), 10304 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.calloc.js delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.complex128.js delete mode 100644 benchmark/benchmark.length.complex64.js delete mode 100644 benchmark/benchmark.length.float32.js delete mode 100644 benchmark/benchmark.length.float64.js delete mode 100644 benchmark/benchmark.length.int16.js delete mode 100644 benchmark/benchmark.length.int32.js delete mode 100644 benchmark/benchmark.length.int8.js delete mode 100644 benchmark/benchmark.length.uint16.js delete mode 100644 benchmark/benchmark.length.uint32.js delete mode 100644 benchmark/benchmark.length.uint8.js delete mode 100644 benchmark/benchmark.length.uint8c.js delete mode 100644 benchmark/benchmark.malloc.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/bytes_per_element.json delete mode 100644 lib/defaults.json delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/pool.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 05e0053..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-12-01T02:49:37.656Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ea35f20..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/array/pool) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 fc6d38a..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/array/pool) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 9ef1395..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 37ddb4f..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,781 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -482,7 +481,7 @@ console.log( 'nbytes: %d', typedarray.nbytes ); ## 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]. @@ -548,7 +547,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm diff --git a/benchmark/benchmark.calloc.js b/benchmark/benchmark.calloc.js deleted file mode 100644 index e5a1c77..0000000 --- a/benchmark/benchmark.calloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':calloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index f7cd676..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = typedarray.factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:highWaterMark', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'highWaterMark': 0 - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.highWaterMark = i; - f = typedarray.factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a023d2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.complex128.js b/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 47b623b..0000000 --- a/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex64.js b/benchmark/benchmark.length.complex64.js deleted file mode 100644 index 40a412b..0000000 --- a/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float32.js b/benchmark/benchmark.length.float32.js deleted file mode 100644 index 0227ed7..0000000 --- a/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float64.js b/benchmark/benchmark.length.float64.js deleted file mode 100644 index 2dbac1c..0000000 --- a/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int16.js b/benchmark/benchmark.length.int16.js deleted file mode 100644 index e2a8adc..0000000 --- a/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int32.js b/benchmark/benchmark.length.int32.js deleted file mode 100644 index e4df0aa..0000000 --- a/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int8.js b/benchmark/benchmark.length.int8.js deleted file mode 100644 index 7ceac11..0000000 --- a/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint16.js b/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 9a532b6..0000000 --- a/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint32.js b/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 98f2d7f..0000000 --- a/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8.js b/benchmark/benchmark.length.uint8.js deleted file mode 100644 index 8359249..0000000 --- a/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8c.js b/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index d47d023..0000000 --- a/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.malloc.js b/benchmark/benchmark.malloc.js deleted file mode 100644 index d4eea72..0000000 --- a/benchmark/benchmark.malloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':malloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 8fce14f..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/array/pool" -click B href "https://github.com/stdlib-js/array-pool/tree/main" -click C href "https://github.com/stdlib-js/array-pool/tree/production" -click D href "https://github.com/stdlib-js/array-pool/tree/esm" -click E href "https://github.com/stdlib-js/array-pool/tree/deno" -click F href "https://github.com/stdlib-js/array-pool/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/pool -[production-url]: https://github.com/stdlib-js/array-pool/tree/production -[deno-url]: https://github.com/stdlib-js/array-pool/tree/deno -[umd-url]: https://github.com/stdlib-js/array-pool/tree/umd -[esm-url]: https://github.com/stdlib-js/array-pool/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5244595..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,347 +0,0 @@ - -{{alias}}( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - Memory is **uninitialized**, which means that the contents of a returned - typed array may contain sensitive contents. - - The function supports the following data types: - - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - The default typed array data type is `float64`. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}() - [] - > arr = {{alias}}( 'float32' ) - [] - - -{{alias}}( length[, dtype] ) - Returns an uninitialized typed array having a specified length from a typed - array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > arr = {{alias}}( 5, 'int32' ) - - - -{{alias}}( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - This method shares the same security vulnerabilities mentioned above. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc() - - > arr = {{alias}}.malloc( 'float32' ) - - - -{{alias}}.malloc( length[, dtype] ) - Returns a typed array having a specified length from a typed array memory - pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc( 5 ) - - > arr = {{alias}}.malloc( 5, 'int32' ) - - - -{{alias}}.malloc( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}.malloc( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.calloc( [dtype] ) - Returns a zero-initialized typed array from a typed array memory pool. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc() - [] - > arr = {{alias}}.calloc( 'float32' ) - [] - - -{{alias}}.calloc( length[, dtype] ) - Returns a zero-initialized typed array having a specified length from a - typed array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}.calloc( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}.free( buf ) - Frees a typed array or typed array buffer for use in a future allocation. - - Parameters - ---------- - buf: TypedArray|ArrayBuffer - Typed array or typed array buffer to free. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ) - - -{{alias}}.clear() - Clears the typed array pool allowing garbage collection of previously - allocated (and currently free) array buffers. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - > {{alias}}.clear() - - -{{alias}}.highWaterMark - Read-only property returning the pool's high water mark. - - Once a high water mark is reached, typed array allocation fails. - - Examples - -------- - > {{alias}}.highWaterMark - - -{{alias}}.nbytes - Read-only property returning the total number of allocated bytes. - - The returned value is the total accumulated value. Hence, anytime a pool - must allocate a new array buffer (i.e., more memory), the pool increments - this value. - - The only time this value is decremented is when a pool is cleared. - - This behavior means that, while allocated buffers which are never freed may, - in fact, be garbage collected, they continue to count against the high water - mark limit. - - Accordingly, you should *always* free allocated buffers in order to prevent - the pool from believing that non-freed buffers are continually in use. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.nbytes - - -{{alias}}.factory( [options] ) - Creates a typed array pool. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.highWaterMark: integer (optional) - Maximum total memory (in bytes) which can be allocated. - - Returns - ------- - fcn: Function - Function for creating typed arrays from a typed array memory pool. - - Examples - -------- - > var pool = {{alias}}.factory(); - > var arr1 = pool( 3, 'float64' ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1014bba..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,193 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-empty */ -/* tslint:disable:no-unused-expression */ - -import typedarraypool = require( './index' ); - - -// TESTS // - -// The function returns a typed array or null... -{ - typedarraypool(); // $ExpectType TypedArrayOrNull - typedarraypool( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the function is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool( true ); // $ExpectError - typedarraypool( false ); // $ExpectError - typedarraypool( null ); // $ExpectError - typedarraypool( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized data type... -{ - typedarraypool( 4, true ); // $ExpectError - typedarraypool( 4, false ); // $ExpectError - typedarraypool( 4, null ); // $ExpectError - typedarraypool( 4, 'abc' ); // $ExpectError - typedarraypool( 4, 123 ); // $ExpectError - typedarraypool( 4, [] ); // $ExpectError - typedarraypool( 4, {} ); // $ExpectError - typedarraypool( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an incorrect number of arguments... -{ - typedarraypool( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `malloc` method which returns a typed array or null... -{ - typedarraypool.malloc(); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.malloc( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `malloc` method is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool.malloc( true ); // $ExpectError - typedarraypool.malloc( false ); // $ExpectError - typedarraypool.malloc( null ); // $ExpectError - typedarraypool.malloc( {} ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.malloc( 4, true ); // $ExpectError - typedarraypool.malloc( 4, false ); // $ExpectError - typedarraypool.malloc( 4, null ); // $ExpectError - typedarraypool.malloc( 4, 'abc' ); // $ExpectError - typedarraypool.malloc( 4, 123 ); // $ExpectError - typedarraypool.malloc( 4, [] ); // $ExpectError - typedarraypool.malloc( 4, {} ); // $ExpectError - typedarraypool.malloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided an incorrect number of arguments... -{ - typedarraypool.malloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `calloc` method which returns a typed array or null... -{ - typedarraypool.calloc(); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `calloc` method is provided a first argument which is not a number... -{ - typedarraypool.calloc( 'abc' ); // $ExpectError - typedarraypool.calloc( true ); // $ExpectError - typedarraypool.calloc( false ); // $ExpectError - typedarraypool.calloc( null ); // $ExpectError - typedarraypool.calloc( {} ); // $ExpectError - typedarraypool.calloc( [] ); // $ExpectError - typedarraypool.calloc( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.calloc( 4, true ); // $ExpectError - typedarraypool.calloc( 4, false ); // $ExpectError - typedarraypool.calloc( 4, null ); // $ExpectError - typedarraypool.calloc( 4, 'abc' ); // $ExpectError - typedarraypool.calloc( 4, 123 ); // $ExpectError - typedarraypool.calloc( 4, [] ); // $ExpectError - typedarraypool.calloc( 4, {} ); // $ExpectError - typedarraypool.calloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided an incorrect number of arguments... -{ - typedarraypool.calloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `factory` method which returns a typed array pool.. -{ - typedarraypool.factory(); // $ExpectType Pool - typedarraypool.factory( { 'highWaterMark': 556 } ); // $ExpectType Pool -} - -// The compiler throws an error if the `factory` method is provided a `highWaterMark` option which is not a number... -{ - typedarraypool.factory( { 'highWaterMark': true } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': false } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': 'abc' } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': null } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': [] } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': {} } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an incorrect number of arguments... -{ - typedarraypool.factory( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` method which returns void... -{ - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.free( arr ); // $ExpectType void -} - -// The compiler throws an error if the `free` method is provided a first argument which is neither a typed array nor array buffer... -{ - typedarraypool.free( true ); // $ExpectError - typedarraypool.free( false ); // $ExpectError - typedarraypool.free( 123 ); // $ExpectError - typedarraypool.free( 'abc' ); // $ExpectError - typedarraypool.free( null ); // $ExpectError - typedarraypool.free( {} ); // $ExpectError - typedarraypool.free( ( x: number ): number => x ); // $ExpectError -} - -// Attached to the main export is a `clear` method which returns void... -{ - typedarraypool.clear(); // $ExpectType void -} - -// The compiler throws an error if the `clear` method is provided arguments... -{ - typedarraypool.clear( {} ); // $ExpectError - typedarraypool.clear( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `highWaterMark` property... -{ - typedarraypool.highWaterMark; // $ExpectType number -} - -// Attached to the main export is a `nbytes` property... -{ - typedarraypool.nbytes; // $ExpectType number -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 24a7846..0000000 --- a/examples/index.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 randu = require( '@stdlib/random-base-randu' ); -var typedarraypool = require( './../lib' ); - -// Create a typed array pool which can allocate at most 1GB: -var typedarray = typedarraypool.factory({ - 'highWaterMark': 1e9 -}); - -// Inspect the pool: -console.log( 'Max bytes: %d', typedarray.highWaterMark ); -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Allocate an array for storing double-precision floating-point numbers: -var arr1 = typedarray( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Fill the array... -var i; -for ( i = 0; i < arr1.length; i++ ) { - arr1[ i ] = randu(); -} - -// Inspect array contents: -console.log( arr1 ); - -// Free the array: -typedarray.free( arr1 ); - -// Allocate another array similar to the previous one: -var arr2 = typedarray( 5, 'float64' ); -// returns - -// Check that we have been returned a new typed array view: -console.log( arr2 === arr1 ); -// => false - -// Inspect array contents: -console.log( arr2 ); - -// Free the array: -typedarray.free( arr2 ); - -// Allocate an initialized array: -var arr3 = typedarray.calloc( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect array contents: -console.log( arr3 ); - -// Free the array: -typedarray.free( arr3 ); - -// Clear the pool: -typedarray.clear(); - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 239fcdc..4500b91 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; import ArrayBuffer = require( '@stdlib/array-buffer' ); diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..d087cb1 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.0.7-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";var w={highWaterMark:9007199254740992};function M(e,t){return y(t)?k(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(f("00d35","highWaterMark",e.highWaterMark)):null:new TypeError(f("00d2h",t))}function W(e){var t,r;for(t=[],r=0;rL.highWaterMark?null:(t=new c(e),k+=e,t)}function z(e,t,r){var s;return 0===t?new e(0):null===(s=q(b(t)*E[r]))?s:new e(s,0,t)}function C(){var e,i,n,l,j,c,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(n=d(i)))throw new TypeError(f("00d2k",i));if(e<=0)return new n(0);if(r(arguments[0]))return z(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,m(l)?l=h(l,0):o(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=z(n,u,i)))return j;if(B(j)||A(j))return j.set(l),j;for(g=p(l).getter,c=p(j).setter,b=0;b0){for(t=u(v(e.byteLength)),t=x(T.length-1,t),r=T[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = copy( defaults );\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '00d2k', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring user's don't do ill-advised things...\n\t\t\tget = arraylike2object( arr ).getter;\n\t\t\tset = arraylike2object( out ).setter;\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '00d33', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","copy","defaults","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","arraylike2object","getter","setter","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;mqEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,QAAS,gBAAiBP,EAAKI,gBAGxD,KARC,IAAIE,UAAWC,EAAQ,QAASN,GASzC,CC/BA,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,iHCaIG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EAAOsB,EAAMC,GACRC,UAAUC,SACdJ,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOkB,EAAYC,EAAMC,EAAM5B,EAAKI,iBACpCgB,EAAS,EAETS,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB9B,EAAKI,eAC3C8B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOf,CACP,CASD,SAASgB,EAAa3B,GACrB,IAAI4B,EACA1B,EAMJ,OAHAA,EAAIiB,EAAMnB,IAGDD,EAAKiB,QAAUjB,EAAMG,GAAIc,OAC1BjB,EAAMG,GAAI2B,MAGblB,EAAOX,EAAIT,EAAKI,cACb,MAERiC,EAAM,IAAIE,EAAa9B,GAGvBW,GAAUX,EAEH4B,EACP,CAWD,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,EACzB,CAkBD,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAxB,EACAP,EACAqC,EACAC,EACAN,EACA/B,EAUJ,GALCgC,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAO3B,EAAO6B,IAEb,MAAM,IAAIrC,UAAWC,EAAQ,QAASoC,IAEvC,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKpC,EAAsBmB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAzB,EAAMO,UAAW,IACPC,OACL0B,EAAmBlC,GACvBA,EAAMmC,EAAgBnC,EAAK,GAChBoC,EAAkBpC,GAC7BA,EAAMqC,EAAerC,EAAK,GACf,WAAWsC,KAAMZ,KAE5BD,GAAO,GAGK,QADbhC,EAAM8B,EAAYC,EAAMC,EAAKC,IAE5B,OAAOjC,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAIqC,IAAK9B,GACFP,EAKR,IAFAsC,EAAMQ,EAAkBvC,GAAMwC,OAC9BV,EAAMS,EAAkB9C,GAAMgD,OACxB/C,EAAI,EAAGA,EAAI+B,EAAK/B,IACrBoC,EAAKrC,EAAKC,EAAGqC,EAAK/B,EAAKN,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,QAASiB,UAAW,IACjD,CAgBD,SAASO,IACR,IAAIe,EACApC,EACAiD,EACAhD,EAUJ,GAAa,QANZD,EADc,KADfoC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCmC,EADIzC,EAAiBR,GACf0C,EAAgB1C,EAAK,GAChBM,EAAgBN,GACrB4C,EAAe5C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAIgD,EAAIlC,OAAQd,IAC5BgD,EAAKhD,GAAM,EAGb,OAAOD,CACP,CAcD,SAASsB,EAAMK,GACd,IAAI5B,EACAmD,EACAjD,EACJ,GAAKkD,EAAkBxB,IAASA,EAAIyB,OACnCzB,EAAMA,EAAIyB,YACJ,IAAMC,EAAe1B,GAC3B,MAAM,IAAI/B,UAAWC,EAAQ,4EAA6E8B,IAE3G,GAAKA,EAAI2B,WAAa,EAAI,CAQzB,IAPAvD,EAAIwD,EAAOrC,EAAMS,EAAI2B,aAGrBvD,EAAIyD,EAAK1D,EAAKiB,OAAO,EAAGhB,GAGxBmD,EAAIpD,EAAMC,GACJE,EAAI,EAAGA,EAAIiD,EAAEnC,OAAQd,IAC1B,GAAKiD,EAAGjD,KAAQ0B,EACf,OAAO,EAITuB,EAAEhD,KAAMyB,EACR,CACD,OAAO,CACP,CAOD,SAASJ,IACR,IAAItB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKiB,OAAQd,IAC7BH,EAAMG,GAAIc,OAAS,EAEpBL,EAAS,CACT,CACF,CCnTG,IAAC+C,EAAiBhD,ICPrBU,EAAAuC,EAAA,UAAAjD"} \ No newline at end of file diff --git a/lib/bytes_per_element.json b/lib/bytes_per_element.json deleted file mode 100644 index f97fe70..0000000 --- a/lib/bytes_per_element.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "float64": 8, - "float32": 4, - "int16": 2, - "int32": 4, - "int8": 1, - "uint16": 2, - "uint32": 4, - "uint8": 1, - "uint8c": 1, - "complex64": 8, - "complex128": 16 -} diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index c71c8f2..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "highWaterMark": 9007199254740992 -} diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index b75e403..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,370 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var isComplex64Array = require( '@stdlib/assert-is-complex64array' ); -var isComplex128Array = require( '@stdlib/assert-is-complex128array' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var ctors = require( '@stdlib/array-typed-ctors' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var copy = require( '@stdlib/utils-copy' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil = require( '@stdlib/math-base-special-ceil' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); -var log2 = require( '@stdlib/math-base-special-log2' ); -var min = require( '@stdlib/math-base-special-min' ); -var defaults = require( './defaults.json' ); -var validate = require( './validate.js' ); -var createPool = require( './pool.js' ); -var BYTES_PER_ELEMENT = require( './bytes_per_element.json' ); - - -// VARIABLES // - -var Complex64Array = ctors( 'complex64' ); -var Complex128Array = ctors( 'complex128' ); - - -// FUNCTIONS // - -/** -* Tests whether an array is a single-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a single-precision complex floating-point number array -*/ -function isCmplx64Array( arr ) { - return ( arr instanceof Complex64Array ); -} - -/** -* Tests whether an array is a double-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a double-precision complex floating-point number array -*/ -function isCmplx128Array( arr ) { - return ( arr instanceof Complex128Array ); -} - - -// MAIN // - -/** -* Creates a typed array pool. -* -* @param {Options} [options] - pool options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} allocator -* -* @example -* var typedarraypool = factory(); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -function factory( options ) { - var nbytes; - var pool; - var opts; - var err; - - opts = copy( defaults ); - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - pool = createPool( ceil( log2( opts.highWaterMark ) ) ); - nbytes = 0; - - setReadOnly( malloc, 'malloc', malloc ); // circular reference - setReadOnly( malloc, 'calloc', calloc ); - setReadOnly( malloc, 'free', free ); - setReadOnly( malloc, 'clear', clear ); - setReadOnly( malloc, 'highWaterMark', opts.highWaterMark ); - setReadOnlyAccessor( malloc, 'nbytes', getBytes ); - - return malloc; - - /** - * Returns the number of allocated bytes. - * - * @private - * @returns {NonNegativeInteger} number of allocated bytes - */ - function getBytes() { - return nbytes; - } - - /** - * Returns an array buffer. - * - * @private - * @param {NonNegativeInteger} n - number of bytes - * @returns {(ArrayBuffer|null)} array buffer or null - */ - function arraybuffer( n ) { - var buf; - var i; - - // Convert the number of bytes to an index in our pool table: - i = log2( n ); - - // If we already have an available array buffer, use it... - if ( i < pool.length && pool[ i ].length ) { - return pool[ i ].pop(); - } - // Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate... - if ( nbytes+n > opts.highWaterMark ) { - return null; - } - buf = new ArrayBuffer( n ); - - // Update the running counter of allocated bytes: - nbytes += n; - - return buf; - } - - /** - * Returns a typed array. - * - * @private - * @param {Function} ctor - typed array constructor - * @param {NonNegativeInteger} len - view length - * @param {string} dtype - data type - * @returns {(TypedArray|null)} typed array or null - */ - function typedarray( ctor, len, dtype ) { - var buf; - if ( len === 0 ) { - return new ctor( 0 ); - } - buf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] ); - if ( buf === null ) { - return buf; - } - return new ctor( buf, 0, len ); - } - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length or an array-like object - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function malloc() { - var nargs; - var dtype; - var ctor; - var arr; - var out; - var set; - var get; - var len; - var i; - - nargs = arguments.length; - if ( nargs && isString( arguments[ nargs-1 ] ) ) { - nargs -= 1; - dtype = arguments[ nargs ]; - } else { - dtype = 'float64'; - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( '00d2k', dtype ) ); - } - if ( nargs <= 0 ) { - return new ctor( 0 ); - } - // Check if provided a typed array length... - if ( isNonNegativeInteger( arguments[ 0 ] ) ) { - return typedarray( ctor, arguments[ 0 ], dtype ); - } - // Check if provided an array-like object containing data elements... - if ( isCollection( arguments[ 0 ] ) ) { - arr = arguments[ 0 ]; - len = arr.length; - if ( isComplex128Array( arr ) ) { - arr = reinterpret128( arr, 0 ); - } else if ( isComplex64Array( arr ) ) { - arr = reinterpret64( arr, 0 ); - } else if ( /^complex/.test( dtype ) ) { - // Assume we've been provided an array of interleaved real and imaginary components... - len /= 2; - } - out = typedarray( ctor, len, dtype ); - if ( out === null ) { - return out; - } - if ( isCmplx128Array( out ) || isCmplx64Array( out ) ) { - out.set( arr ); - return out; - } - // Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other "unsafe" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring user's don't do ill-advised things... - get = arraylike2object( arr ).getter; - set = arraylike2object( out ).setter; - for ( i = 0; i < len; i++ ) { - set( out, i, get( arr, i ) ); - } - return out; - } - throw new TypeError( format( '00d33', arguments[ 0 ] ) ); - } - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {NonNegativeInteger} [len=0] - array length - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function calloc() { - var nargs; - var out; - var tmp; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - out = malloc(); - } else if ( nargs === 1 ) { - out = malloc( arguments[ 0 ] ); - } else { - out = malloc( arguments[ 0 ], arguments[ 1 ] ); - } - if ( out !== null ) { - // Initialize the memory... - if ( isCmplx128Array( out ) ) { - tmp = reinterpret128( out, 0 ); - } else if ( isCmplx64Array( out ) ) { - tmp = reinterpret64( out, 0 ); - } else { - tmp = out; - } - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = 0.0; - } - } - return out; - } - - /** - * Frees a typed array or typed array buffer. - * - * ## Notes - * - * - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., "freeing" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool. - * - * @private - * @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free - * @throws {TypeError} must provide a typed array or typed array buffer - * @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed - */ - function free( buf ) { - var n; - var p; - var i; - if ( isTypedArrayLike( buf ) && buf.buffer ) { - buf = buf.buffer; - } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) ); - } - if ( buf.byteLength > 0 ) { - n = floor( log2( buf.byteLength ) ); - - // Prohibit "freeing" array buffers which would potentially allow users to circumvent high water mark limits: - n = min( pool.length-1, n ); - - // Ensure that we do not attempt to free the same buffer more than once... - p = pool[ n ]; - for ( i = 0; i < p.length; i++ ) { - if ( p[ i ] === buf ) { - return false; - } - } - // Add the buffer to our pool of free buffers: - p.push( buf ); - } - return true; - } - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @private - */ - function clear() { - var i; - for ( i = 0; i < pool.length; i++ ) { - pool[ i ].length = 0; - } - nbytes = 0; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6c12a4e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Typed array pool. -* -* @module @stdlib/array-pool -* -* @example -* var typedarraypool = require( '@stdlib/array-pool' ); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8f69ee3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,63 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @name typedarraypool -* @type {Function} -* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a valid array length or an array-like object -* @throws {TypeError} must provide a recognized data type -* @returns {(TypedArray|null)} typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -var typedarraypool = factory(); - - -// EXPORTS // - -module.exports = typedarraypool; diff --git a/lib/pool.js b/lib/pool.js deleted file mode 100644 index 5abd287..0000000 --- a/lib/pool.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Initializes a cache for pooled typed array buffers. -* -* @private -* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size -* @returns {ArrayArray} initialized cache -*/ -function pool( n ) { - var out; - var i; - - out = []; - for ( i = 0; i < n+1; i++ ) { - out.push( [] ); - } - return out; -} - - -// EXPORTS // - -module.exports = pool; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 4135ec9..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'highWaterMark': 1024 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '00d2h', options ) ); - } - if ( hasOwnProp( options, 'highWaterMark' ) ) { - opts.highWaterMark = options.highWaterMark; - if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( '00d35', 'highWaterMark', opts.highWaterMark ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 34e736e..42614cf 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Typed array pool.", "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,76 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.0.x", - "@stdlib/array-buffer": "^0.0.x", - "@stdlib/array-typed-ctors": "^0.0.x", - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-arraybuffer": "^0.0.x", - "@stdlib/assert-is-collection": "^0.0.x", - "@stdlib/assert-is-complex128array": "^0.0.x", - "@stdlib/assert-is-complex64array": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/assert-is-string": "^0.0.x", - "@stdlib/assert-is-typed-array-like": "^0.0.x", - "@stdlib/math-base-special-ceil": "^0.0.x", - "@stdlib/math-base-special-ceil2": "^0.0.x", - "@stdlib/math-base-special-floor": "^0.0.x", - "@stdlib/math-base-special-log2": "^0.0.x", - "@stdlib/math-base-special-min": "^0.0.x", - "@stdlib/strided-base-reinterpret-complex128": "^0.0.x", - "@stdlib/strided-base-reinterpret-complex64": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-copy": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.x", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.0.x", - "@stdlib/array-complex64": "^0.0.x", - "@stdlib/array-float32": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/array-int16": "^0.0.x", - "@stdlib/array-int32": "^0.0.x", - "@stdlib/array-int8": "^0.0.x", - "@stdlib/array-uint16": "^0.0.x", - "@stdlib/array-uint32": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/array-uint8c": "^0.0.x", - "@stdlib/assert-instance-of": "^0.0.x", - "@stdlib/assert-is-complex-typed-array": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-typed-array": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/complex-float32": "^0.0.x", - "@stdlib/complex-float64": "^0.0.x", - "@stdlib/complex-imag": "^0.0.x", - "@stdlib/complex-imagf": "^0.0.x", - "@stdlib/complex-real": "^0.0.x", - "@stdlib/complex-realf": "^0.0.x", - "@stdlib/math-base-special-pow": "^0.0.x", - "@stdlib/random-base-randu": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "2.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..634ce64 --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 396aee2..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,2240 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function (no options)', function test( t ) { - t.strictEqual( typeof factory(), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - t.strictEqual( typeof factory( {} ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided a `highWaterMark` option which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (length)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a function which returns a typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, length)', function test( t ) { - var typedarraypool = factory(); - var arr; - - arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a `malloc` method which is a circular reference', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - var buf; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the returned function is a property which returns the pool\'s high water mark', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function supports specifying a high water mark which limits the total amount of memory a pool can allocate', function test( t ) { - var typedarraypool; - var arr1; - var arr2; - - typedarraypool = factory({ - 'highWaterMark': 64 // bytes - }); - - typedarraypool.clear(); - - arr1 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr1.length, 8, 'returns expected value' ); - t.strictEqual( arr1.byteLength, 64, 'returns expected value' ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - typedarraypool.free( arr1 ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Create an array which is less than or equal to the high water mark: - arr2 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr2.length, 8, 'returns expected value' ); - t.strictEqual( arr2.byteLength, 64, 'returns expected value' ); - - typedarraypool.free( arr2 ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a property which returns the total number of accumulated bytes', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var typedarraypool; - var arrs; - var i; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 54aa5ee..0000000 --- a/test/test.js +++ /dev/null @@ -1,1797 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var typedarraypool = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -}); From 64be95b17a0b0d6b5736adeb0d11df686cece66e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 22 Jul 2023 02:28:15 +0000 Subject: [PATCH 029/103] Transform error messages --- lib/factory.js | 6 +++--- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index edfecbe..bc85f86 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -34,7 +34,7 @@ var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); var accessors = require( '@stdlib/array-base-accessors' ); var adtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ArrayBuffer = require( '@stdlib/array-buffer' ); var ceil = require( '@stdlib/math-base-special-ceil' ); var floor = require( '@stdlib/math-base-special-floor' ); @@ -226,7 +226,7 @@ function factory( options ) { } ctor = ctors( dtype ); if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '00d2k', dtype ) ); } if ( nargs <= 0 ) { return new ctor( 0 ); @@ -263,7 +263,7 @@ function factory( options ) { } return out; } - throw new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) ); + throw new TypeError( format( '00d33', arguments[ 0 ] ) ); } /** diff --git a/lib/validate.js b/lib/validate.js index ce54890..4135ec9 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '00d2h', options ) ); } if ( hasOwnProp( options, 'highWaterMark' ) ) { opts.highWaterMark = options.highWaterMark; if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) ); + return new TypeError( format( '00d35', 'highWaterMark', opts.highWaterMark ) ); } } return null; diff --git a/package.json b/package.json index 5151fc3..7d353bb 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "@stdlib/math-base-special-min": "^0.0.7", "@stdlib/strided-base-reinterpret-complex128": "^0.0.2", "@stdlib/strided-base-reinterpret-complex64": "^0.0.2", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.7", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7" From 50ab1b2b5147cada6d0a9ea35211b4f2df6d733b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 22 Jul 2023 02:28:51 +0000 Subject: [PATCH 030/103] Remove files --- index.d.ts | 359 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4408 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 4500b91..0000000 --- a/index.d.ts +++ /dev/null @@ -1,359 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; -import ArrayBuffer = require( '@stdlib/array-buffer' ); - -/** -* Typed array or null. -*/ -type TypedArrayOrNull = RealOrComplexTypedArray | null; - -/** -* Interface defining pool options. -*/ -interface Options { - /** - * Maximum total memory which can be allocated. - */ - highWaterMark?: number; -} - -/** -* Pool interface. -*/ -interface Pool { - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr = typedarraypool(); - * // returns [] - * - * @example - * var arr = typedarraypool( 'float32' ); - * // returns [] - */ - ( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * // Allocate an array of doubles: - * var arr = typedarraypool( 5, 'float64' ); - * // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * typedarraypool.free( arr ); - * - * @example - * var arr1 = typedarraypool( [ 0.5, 0.5, 0.5 ] ); - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * @example - * var arr1 = [ 0.5, 0.5, 0.5 ]; - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - */ - ( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc(); - * // returns [] - * - * var arr2 = typedarraypool.calloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param length - typed array length - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc( 5 ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * var arr2 = typedarraypool.calloc( 5, 'uint8' ); - * // returns [ 0, 0, 0, 0, 0 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( length: number, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc(); - * // returns [] - * - * var arr2 = typedarraypool.malloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc( 5 ); - * // returns - * - * var arr2 = typedarraypool.malloc( 5, 'uint8' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 5.0, -3.0, 2.0 ] ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr2 = typedarraypool.malloc( arr1 ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr3 = typedarraypool.malloc( arr1, 'int32' ); - * // returns [ 5, -3, 2 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * typedarraypool.free( arr3 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ] ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * var arr2 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ], 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Frees a typed array or typed array buffer for use in a future allocation. - * - * @param buf - typed array or typed array buffer to free - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array for use in a future allocation: - * typedarraypool.free( arr ); - * - * // Create another typed array: - * arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array buffer for use in a future allocation: - * typedarraypool.free( arr.buffer ); - */ - free( buf: RealOrComplexTypedArray | ArrayBuffer ): void; - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr ); - * - * // ... - * - * // Clear all freed buffers: - * typedarraypool.clear(); - */ - clear(): void; - - /** - * Read-only property returning the pool's high water mark. - * - * ## Notes - * - * - Once a high water mark is reached, typed array allocation fails. - * - * @example - * var limit = typedarraypool.highWaterMark; - * // returns - */ - readonly highWaterMark: number; - - /** - * Read-only property returning the total number of allocated bytes. - * - * @example - * var arr = typedarraypool( 5, 'float64' ); - * - * var nbytes = typedarraypool.nbytes; - * // returns - */ - readonly nbytes: number; - - /** - * Creates a typed array pool. - * - * @param options - pool options - * @param options.highWaterMark - maximum total memory which can be allocated - * @throws must provide valid options - * @returns allocator - * - * @example - * var allocator = typedarraypool.factory(); - * - * // Allocate an array of doubles: - * var arr = allocator( 5, 'float64' ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * allocator.free( arr ); - */ - factory( options?: Options ): Pool; -} - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @param arg - an array length or an array-like object -* @param dtype - data type (default: 'float64') -* @returns typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -declare var typedarraypool: Pool; - - -// EXPORTS // - -export = typedarraypool; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index d087cb1..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-copy@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.0.7-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";var w={highWaterMark:9007199254740992};function M(e,t){return y(t)?k(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(f("00d35","highWaterMark",e.highWaterMark)):null:new TypeError(f("00d2h",t))}function W(e){var t,r;for(t=[],r=0;rL.highWaterMark?null:(t=new c(e),k+=e,t)}function z(e,t,r){var s;return 0===t?new e(0):null===(s=q(b(t)*E[r]))?s:new e(s,0,t)}function C(){var e,i,n,l,j,c,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(n=d(i)))throw new TypeError(f("00d2k",i));if(e<=0)return new n(0);if(r(arguments[0]))return z(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,m(l)?l=h(l,0):o(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=z(n,u,i)))return j;if(B(j)||A(j))return j.set(l),j;for(g=p(l).getter,c=p(j).setter,b=0;b0){for(t=u(v(e.byteLength)),t=x(T.length-1,t),r=T[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = copy( defaults );\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '00d2k', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring user's don't do ill-advised things...\n\t\t\tget = arraylike2object( arr ).getter;\n\t\t\tset = arraylike2object( out ).setter;\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '00d33', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","copy","defaults","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","arraylike2object","getter","setter","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;mqEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,QAAS,gBAAiBP,EAAKI,gBAGxD,KARC,IAAIE,UAAWC,EAAQ,QAASN,GASzC,CC/BA,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,iHCaIG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EAAOsB,EAAMC,GACRC,UAAUC,SACdJ,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOkB,EAAYC,EAAMC,EAAM5B,EAAKI,iBACpCgB,EAAS,EAETS,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB9B,EAAKI,eAC3C8B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOf,CACP,CASD,SAASgB,EAAa3B,GACrB,IAAI4B,EACA1B,EAMJ,OAHAA,EAAIiB,EAAMnB,IAGDD,EAAKiB,QAAUjB,EAAMG,GAAIc,OAC1BjB,EAAMG,GAAI2B,MAGblB,EAAOX,EAAIT,EAAKI,cACb,MAERiC,EAAM,IAAIE,EAAa9B,GAGvBW,GAAUX,EAEH4B,EACP,CAWD,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,EACzB,CAkBD,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAxB,EACAP,EACAqC,EACAC,EACAN,EACA/B,EAUJ,GALCgC,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAO3B,EAAO6B,IAEb,MAAM,IAAIrC,UAAWC,EAAQ,QAASoC,IAEvC,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKpC,EAAsBmB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAzB,EAAMO,UAAW,IACPC,OACL0B,EAAmBlC,GACvBA,EAAMmC,EAAgBnC,EAAK,GAChBoC,EAAkBpC,GAC7BA,EAAMqC,EAAerC,EAAK,GACf,WAAWsC,KAAMZ,KAE5BD,GAAO,GAGK,QADbhC,EAAM8B,EAAYC,EAAMC,EAAKC,IAE5B,OAAOjC,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAIqC,IAAK9B,GACFP,EAKR,IAFAsC,EAAMQ,EAAkBvC,GAAMwC,OAC9BV,EAAMS,EAAkB9C,GAAMgD,OACxB/C,EAAI,EAAGA,EAAI+B,EAAK/B,IACrBoC,EAAKrC,EAAKC,EAAGqC,EAAK/B,EAAKN,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,QAASiB,UAAW,IACjD,CAgBD,SAASO,IACR,IAAIe,EACApC,EACAiD,EACAhD,EAUJ,GAAa,QANZD,EADc,KADfoC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCmC,EADIzC,EAAiBR,GACf0C,EAAgB1C,EAAK,GAChBM,EAAgBN,GACrB4C,EAAe5C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAIgD,EAAIlC,OAAQd,IAC5BgD,EAAKhD,GAAM,EAGb,OAAOD,CACP,CAcD,SAASsB,EAAMK,GACd,IAAI5B,EACAmD,EACAjD,EACJ,GAAKkD,EAAkBxB,IAASA,EAAIyB,OACnCzB,EAAMA,EAAIyB,YACJ,IAAMC,EAAe1B,GAC3B,MAAM,IAAI/B,UAAWC,EAAQ,4EAA6E8B,IAE3G,GAAKA,EAAI2B,WAAa,EAAI,CAQzB,IAPAvD,EAAIwD,EAAOrC,EAAMS,EAAI2B,aAGrBvD,EAAIyD,EAAK1D,EAAKiB,OAAO,EAAGhB,GAGxBmD,EAAIpD,EAAMC,GACJE,EAAI,EAAGA,EAAIiD,EAAEnC,OAAQd,IAC1B,GAAKiD,EAAGjD,KAAQ0B,EACf,OAAO,EAITuB,EAAEhD,KAAMyB,EACR,CACD,OAAO,CACP,CAOD,SAASJ,IACR,IAAItB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKiB,OAAQd,IAC7BH,EAAMG,GAAIc,OAAS,EAEpBL,EAAS,CACT,CACF,CCnTG,IAAC+C,EAAiBhD,ICPrBU,EAAAuC,EAAA,UAAAjD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 634ce64..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 55074c1fe2f07d917ba841d8273bb492adfe5ccf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 22 Jul 2023 02:29:47 +0000 Subject: [PATCH 031/103] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 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 | 43 +- benchmark/benchmark.calloc.js | 246 - benchmark/benchmark.factory.js | 71 - benchmark/benchmark.js | 246 - benchmark/benchmark.length.complex128.js | 102 - benchmark/benchmark.length.complex64.js | 102 - benchmark/benchmark.length.float32.js | 102 - benchmark/benchmark.length.float64.js | 102 - benchmark/benchmark.length.int16.js | 102 - benchmark/benchmark.length.int32.js | 102 - benchmark/benchmark.length.int8.js | 102 - benchmark/benchmark.length.uint16.js | 102 - benchmark/benchmark.length.uint32.js | 102 - benchmark/benchmark.length.uint8.js | 102 - benchmark/benchmark.length.uint8c.js | 102 - benchmark/benchmark.malloc.js | 246 - branches.md | 53 - docs/repl.txt | 347 -- docs/types/test.ts | 193 - examples/index.js | 80 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/bytes_per_element.json | 13 - lib/defaults.js | 42 - lib/factory.js | 370 -- lib/index.js | 56 - lib/main.js | 63 - lib/pool.js | 44 - lib/validate.js | 66 - package.json | 97 +- stats.html | 6177 +++++++++++++++++++++ test/test.factory.js | 2240 -------- test/test.js | 1797 ------ 56 files changed, 6206 insertions(+), 10494 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.calloc.js delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.complex128.js delete mode 100644 benchmark/benchmark.length.complex64.js delete mode 100644 benchmark/benchmark.length.float32.js delete mode 100644 benchmark/benchmark.length.float64.js delete mode 100644 benchmark/benchmark.length.int16.js delete mode 100644 benchmark/benchmark.length.int32.js delete mode 100644 benchmark/benchmark.length.int8.js delete mode 100644 benchmark/benchmark.length.uint16.js delete mode 100644 benchmark/benchmark.length.uint32.js delete mode 100644 benchmark/benchmark.length.uint8.js delete mode 100644 benchmark/benchmark.length.uint8c.js delete mode 100644 benchmark/benchmark.malloc.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/bytes_per_element.json delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/pool.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ea35f20..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/array/pool) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 fc6d38a..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/array/pool) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 9ef1395..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -482,7 +481,7 @@ console.log( 'nbytes: %d', typedarray.nbytes ); ## 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]. @@ -548,7 +547,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm diff --git a/benchmark/benchmark.calloc.js b/benchmark/benchmark.calloc.js deleted file mode 100644 index e5a1c77..0000000 --- a/benchmark/benchmark.calloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':calloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index f7cd676..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = typedarray.factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:highWaterMark', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'highWaterMark': 0 - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.highWaterMark = i; - f = typedarray.factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a023d2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.complex128.js b/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 47b623b..0000000 --- a/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex64.js b/benchmark/benchmark.length.complex64.js deleted file mode 100644 index 40a412b..0000000 --- a/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float32.js b/benchmark/benchmark.length.float32.js deleted file mode 100644 index 0227ed7..0000000 --- a/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float64.js b/benchmark/benchmark.length.float64.js deleted file mode 100644 index 2dbac1c..0000000 --- a/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int16.js b/benchmark/benchmark.length.int16.js deleted file mode 100644 index e2a8adc..0000000 --- a/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int32.js b/benchmark/benchmark.length.int32.js deleted file mode 100644 index e4df0aa..0000000 --- a/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int8.js b/benchmark/benchmark.length.int8.js deleted file mode 100644 index 7ceac11..0000000 --- a/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint16.js b/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 9a532b6..0000000 --- a/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint32.js b/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 98f2d7f..0000000 --- a/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8.js b/benchmark/benchmark.length.uint8.js deleted file mode 100644 index 8359249..0000000 --- a/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8c.js b/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index d47d023..0000000 --- a/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.malloc.js b/benchmark/benchmark.malloc.js deleted file mode 100644 index d4eea72..0000000 --- a/benchmark/benchmark.malloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':malloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 9689761..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/array/pool" -%% click B href "https://github.com/stdlib-js/array-pool/tree/main" -%% click C href "https://github.com/stdlib-js/array-pool/tree/production" -%% click D href "https://github.com/stdlib-js/array-pool/tree/esm" -%% click E href "https://github.com/stdlib-js/array-pool/tree/deno" -%% click F href "https://github.com/stdlib-js/array-pool/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/pool -[production-url]: https://github.com/stdlib-js/array-pool/tree/production -[deno-url]: https://github.com/stdlib-js/array-pool/tree/deno -[umd-url]: https://github.com/stdlib-js/array-pool/tree/umd -[esm-url]: https://github.com/stdlib-js/array-pool/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5244595..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,347 +0,0 @@ - -{{alias}}( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - Memory is **uninitialized**, which means that the contents of a returned - typed array may contain sensitive contents. - - The function supports the following data types: - - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - The default typed array data type is `float64`. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}() - [] - > arr = {{alias}}( 'float32' ) - [] - - -{{alias}}( length[, dtype] ) - Returns an uninitialized typed array having a specified length from a typed - array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > arr = {{alias}}( 5, 'int32' ) - - - -{{alias}}( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - This method shares the same security vulnerabilities mentioned above. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc() - - > arr = {{alias}}.malloc( 'float32' ) - - - -{{alias}}.malloc( length[, dtype] ) - Returns a typed array having a specified length from a typed array memory - pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc( 5 ) - - > arr = {{alias}}.malloc( 5, 'int32' ) - - - -{{alias}}.malloc( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}.malloc( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.calloc( [dtype] ) - Returns a zero-initialized typed array from a typed array memory pool. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc() - [] - > arr = {{alias}}.calloc( 'float32' ) - [] - - -{{alias}}.calloc( length[, dtype] ) - Returns a zero-initialized typed array having a specified length from a - typed array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}.calloc( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}.free( buf ) - Frees a typed array or typed array buffer for use in a future allocation. - - Parameters - ---------- - buf: TypedArray|ArrayBuffer - Typed array or typed array buffer to free. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ) - - -{{alias}}.clear() - Clears the typed array pool allowing garbage collection of previously - allocated (and currently free) array buffers. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - > {{alias}}.clear() - - -{{alias}}.highWaterMark - Read-only property returning the pool's high water mark. - - Once a high water mark is reached, typed array allocation fails. - - Examples - -------- - > {{alias}}.highWaterMark - - -{{alias}}.nbytes - Read-only property returning the total number of allocated bytes. - - The returned value is the total accumulated value. Hence, anytime a pool - must allocate a new array buffer (i.e., more memory), the pool increments - this value. - - The only time this value is decremented is when a pool is cleared. - - This behavior means that, while allocated buffers which are never freed may, - in fact, be garbage collected, they continue to count against the high water - mark limit. - - Accordingly, you should *always* free allocated buffers in order to prevent - the pool from believing that non-freed buffers are continually in use. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.nbytes - - -{{alias}}.factory( [options] ) - Creates a typed array pool. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.highWaterMark: integer (optional) - Maximum total memory (in bytes) which can be allocated. - - Returns - ------- - fcn: Function - Function for creating typed arrays from a typed array memory pool. - - Examples - -------- - > var pool = {{alias}}.factory(); - > var arr1 = pool( 3, 'float64' ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1014bba..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,193 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-empty */ -/* tslint:disable:no-unused-expression */ - -import typedarraypool = require( './index' ); - - -// TESTS // - -// The function returns a typed array or null... -{ - typedarraypool(); // $ExpectType TypedArrayOrNull - typedarraypool( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the function is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool( true ); // $ExpectError - typedarraypool( false ); // $ExpectError - typedarraypool( null ); // $ExpectError - typedarraypool( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized data type... -{ - typedarraypool( 4, true ); // $ExpectError - typedarraypool( 4, false ); // $ExpectError - typedarraypool( 4, null ); // $ExpectError - typedarraypool( 4, 'abc' ); // $ExpectError - typedarraypool( 4, 123 ); // $ExpectError - typedarraypool( 4, [] ); // $ExpectError - typedarraypool( 4, {} ); // $ExpectError - typedarraypool( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an incorrect number of arguments... -{ - typedarraypool( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `malloc` method which returns a typed array or null... -{ - typedarraypool.malloc(); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.malloc( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `malloc` method is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool.malloc( true ); // $ExpectError - typedarraypool.malloc( false ); // $ExpectError - typedarraypool.malloc( null ); // $ExpectError - typedarraypool.malloc( {} ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.malloc( 4, true ); // $ExpectError - typedarraypool.malloc( 4, false ); // $ExpectError - typedarraypool.malloc( 4, null ); // $ExpectError - typedarraypool.malloc( 4, 'abc' ); // $ExpectError - typedarraypool.malloc( 4, 123 ); // $ExpectError - typedarraypool.malloc( 4, [] ); // $ExpectError - typedarraypool.malloc( 4, {} ); // $ExpectError - typedarraypool.malloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided an incorrect number of arguments... -{ - typedarraypool.malloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `calloc` method which returns a typed array or null... -{ - typedarraypool.calloc(); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `calloc` method is provided a first argument which is not a number... -{ - typedarraypool.calloc( 'abc' ); // $ExpectError - typedarraypool.calloc( true ); // $ExpectError - typedarraypool.calloc( false ); // $ExpectError - typedarraypool.calloc( null ); // $ExpectError - typedarraypool.calloc( {} ); // $ExpectError - typedarraypool.calloc( [] ); // $ExpectError - typedarraypool.calloc( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.calloc( 4, true ); // $ExpectError - typedarraypool.calloc( 4, false ); // $ExpectError - typedarraypool.calloc( 4, null ); // $ExpectError - typedarraypool.calloc( 4, 'abc' ); // $ExpectError - typedarraypool.calloc( 4, 123 ); // $ExpectError - typedarraypool.calloc( 4, [] ); // $ExpectError - typedarraypool.calloc( 4, {} ); // $ExpectError - typedarraypool.calloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided an incorrect number of arguments... -{ - typedarraypool.calloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `factory` method which returns a typed array pool.. -{ - typedarraypool.factory(); // $ExpectType Pool - typedarraypool.factory( { 'highWaterMark': 556 } ); // $ExpectType Pool -} - -// The compiler throws an error if the `factory` method is provided a `highWaterMark` option which is not a number... -{ - typedarraypool.factory( { 'highWaterMark': true } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': false } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': 'abc' } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': null } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': [] } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': {} } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an incorrect number of arguments... -{ - typedarraypool.factory( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` method which returns void... -{ - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.free( arr ); // $ExpectType void -} - -// The compiler throws an error if the `free` method is provided a first argument which is neither a typed array nor array buffer... -{ - typedarraypool.free( true ); // $ExpectError - typedarraypool.free( false ); // $ExpectError - typedarraypool.free( 123 ); // $ExpectError - typedarraypool.free( 'abc' ); // $ExpectError - typedarraypool.free( null ); // $ExpectError - typedarraypool.free( {} ); // $ExpectError - typedarraypool.free( ( x: number ): number => x ); // $ExpectError -} - -// Attached to the main export is a `clear` method which returns void... -{ - typedarraypool.clear(); // $ExpectType void -} - -// The compiler throws an error if the `clear` method is provided arguments... -{ - typedarraypool.clear( {} ); // $ExpectError - typedarraypool.clear( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `highWaterMark` property... -{ - typedarraypool.highWaterMark; // $ExpectType number -} - -// Attached to the main export is a `nbytes` property... -{ - typedarraypool.nbytes; // $ExpectType number -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 24a7846..0000000 --- a/examples/index.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 randu = require( '@stdlib/random-base-randu' ); -var typedarraypool = require( './../lib' ); - -// Create a typed array pool which can allocate at most 1GB: -var typedarray = typedarraypool.factory({ - 'highWaterMark': 1e9 -}); - -// Inspect the pool: -console.log( 'Max bytes: %d', typedarray.highWaterMark ); -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Allocate an array for storing double-precision floating-point numbers: -var arr1 = typedarray( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Fill the array... -var i; -for ( i = 0; i < arr1.length; i++ ) { - arr1[ i ] = randu(); -} - -// Inspect array contents: -console.log( arr1 ); - -// Free the array: -typedarray.free( arr1 ); - -// Allocate another array similar to the previous one: -var arr2 = typedarray( 5, 'float64' ); -// returns - -// Check that we have been returned a new typed array view: -console.log( arr2 === arr1 ); -// => false - -// Inspect array contents: -console.log( arr2 ); - -// Free the array: -typedarray.free( arr2 ); - -// Allocate an initialized array: -var arr3 = typedarray.calloc( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect array contents: -console.log( arr3 ); - -// Free the array: -typedarray.free( arr3 ); - -// Clear the pool: -typedarray.clear(); - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 239fcdc..4500b91 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; import ArrayBuffer = require( '@stdlib/array-buffer' ); diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..379878d --- /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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessors@v0.0.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.0.7-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";function k(e,t){return y(t)?w(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(c("00d35","highWaterMark",e.highWaterMark)):null:new TypeError(c("00d2h",t))}function M(e){var t,r;for(t=[],r=0;rT.highWaterMark?null:(t=new j(e),w+=e,t)}function q(e,t,r){var s;return 0===t?new e(0):null===(s=V(b(t)*W[r]))?s:new e(s,0,t)}function z(){var e,i,n,d,j,g,u,b,v;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(n=l(i)))throw new TypeError(c("00d2k",i));if(e<=0)return new n(0);if(r(arguments[0]))return q(n,arguments[0],i);if(s(arguments[0])){if(b=(d=arguments[0]).length,m(d)?d=h(d,0):o(d)?d=a(d,0):/^complex/.test(i)&&(b/=2),null===(j=q(n,b,i)))return j;if(A(j)||L(j))return j.set(d),j;for(u=p(f(d)).accessors[0],g=p(i).accessors[1],v=0;v0){for(t=u(v(e.byteLength)),t=x(E.length-1,t),r=E[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '00d2k', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = accessors( adtype( arr ) ).accessors[ 0 ];\n\t\t\tset = accessors( dtype ).accessors[ 1 ];\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '00d33', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","accessors","adtype","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;6nEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,QAAS,gBAAiBP,EAAKI,gBAGxD,KARC,IAAIE,UAAWC,EAAQ,QAASN,GASzC,CC/BA,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,iHCaIG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EC/EO,CACNI,cAAiB,kBD+EbkB,UAAUC,SACdF,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOgB,EAAYC,EAAMC,EAAM1B,EAAKI,iBACpCgB,EAAS,EAETO,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB5B,EAAKI,eAC3C4B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOb,CACP,CASD,SAASc,EAAazB,GACrB,IAAI0B,EACAxB,EAMJ,OAHAA,EAAIe,EAAMjB,IAGDD,EAAKe,QAAUf,EAAMG,GAAIY,OAC1Bf,EAAMG,GAAIyB,MAGbhB,EAAOX,EAAIT,EAAKI,cACb,MAER+B,EAAM,IAAIE,EAAa5B,GAGvBW,GAAUX,EAEH0B,EACP,CAWD,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,EACzB,CAkBD,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAtB,EACAP,EACAmC,EACAC,EACAN,EACA7B,EAUJ,GALC8B,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAOzB,EAAO2B,IAEb,MAAM,IAAInC,UAAWC,EAAQ,QAASkC,IAEvC,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKlC,EAAsBiB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAvB,EAAMK,UAAW,IACPC,OACL0B,EAAmBhC,GACvBA,EAAMiC,EAAgBjC,EAAK,GAChBkC,EAAkBlC,GAC7BA,EAAMmC,EAAenC,EAAK,GACf,WAAWoC,KAAMZ,KAE5BD,GAAO,GAGK,QADb9B,EAAM4B,EAAYC,EAAMC,EAAKC,IAE5B,OAAO/B,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAImC,IAAK5B,GACFP,EAKR,IAFAoC,EAAMQ,EAAWC,EAAQtC,IAAQqC,UAAW,GAC5CT,EAAMS,EAAWb,GAAQa,UAAW,GAC9B3C,EAAI,EAAGA,EAAI6B,EAAK7B,IACrBkC,EAAKnC,EAAKC,EAAGmC,EAAK7B,EAAKN,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,QAASe,UAAW,IACjD,CAgBD,SAASO,IACR,IAAIe,EACAlC,EACA8C,EACA7C,EAUJ,GAAa,QANZD,EADc,KADfkC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCkC,EADItC,EAAiBR,GACfwC,EAAgBxC,EAAK,GAChBM,EAAgBN,GACrB0C,EAAe1C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAI6C,EAAIjC,OAAQZ,IAC5B6C,EAAK7C,GAAM,EAGb,OAAOD,CACP,CAcD,SAASoB,EAAMK,GACd,IAAI1B,EACAgD,EACA9C,EACJ,GAAK+C,EAAkBvB,IAASA,EAAIwB,OACnCxB,EAAMA,EAAIwB,YACJ,IAAMC,EAAezB,GAC3B,MAAM,IAAI7B,UAAWC,EAAQ,4EAA6E4B,IAE3G,GAAKA,EAAI0B,WAAa,EAAI,CAQzB,IAPApD,EAAIqD,EAAOpC,EAAMS,EAAI0B,aAGrBpD,EAAIsD,EAAKvD,EAAKe,OAAO,EAAGd,GAGxBgD,EAAIjD,EAAMC,GACJE,EAAI,EAAGA,EAAI8C,EAAElC,OAAQZ,IAC1B,GAAK8C,EAAG9C,KAAQwB,EACf,OAAO,EAITsB,EAAE7C,KAAMuB,EACR,CACD,OAAO,CACP,CAOD,SAASJ,IACR,IAAIpB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKe,OAAQZ,IAC7BH,EAAMG,GAAIY,OAAS,EAEpBH,EAAS,CACT,CACF,CEnTG,IAAC4C,EAAiB7C,ICPrBQ,EAAAsC,EAAA,UAAA9C"} \ No newline at end of file diff --git a/lib/bytes_per_element.json b/lib/bytes_per_element.json deleted file mode 100644 index f97fe70..0000000 --- a/lib/bytes_per_element.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "float64": 8, - "float32": 4, - "int16": 2, - "int32": 4, - "int8": 1, - "uint16": 2, - "uint32": 4, - "uint8": 1, - "uint8c": 1, - "complex64": 8, - "complex128": 16 -} diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index a421711..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +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'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'highWaterMark': 9007199254740992 - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index bc85f86..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,370 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var isComplex64Array = require( '@stdlib/assert-is-complex64array' ); -var isComplex128Array = require( '@stdlib/assert-is-complex128array' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var ctors = require( '@stdlib/array-typed-ctors' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var accessors = require( '@stdlib/array-base-accessors' ); -var adtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil = require( '@stdlib/math-base-special-ceil' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); -var log2 = require( '@stdlib/math-base-special-log2' ); -var min = require( '@stdlib/math-base-special-min' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var createPool = require( './pool.js' ); -var BYTES_PER_ELEMENT = require( './bytes_per_element.json' ); - - -// VARIABLES // - -var Complex64Array = ctors( 'complex64' ); -var Complex128Array = ctors( 'complex128' ); - - -// FUNCTIONS // - -/** -* Tests whether an array is a single-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a single-precision complex floating-point number array -*/ -function isCmplx64Array( arr ) { - return ( arr instanceof Complex64Array ); -} - -/** -* Tests whether an array is a double-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a double-precision complex floating-point number array -*/ -function isCmplx128Array( arr ) { - return ( arr instanceof Complex128Array ); -} - - -// MAIN // - -/** -* Creates a typed array pool. -* -* @param {Options} [options] - pool options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} allocator -* -* @example -* var typedarraypool = factory(); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -function factory( options ) { - var nbytes; - var pool; - var opts; - var err; - - opts = defaults(); - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - pool = createPool( ceil( log2( opts.highWaterMark ) ) ); - nbytes = 0; - - setReadOnly( malloc, 'malloc', malloc ); // circular reference - setReadOnly( malloc, 'calloc', calloc ); - setReadOnly( malloc, 'free', free ); - setReadOnly( malloc, 'clear', clear ); - setReadOnly( malloc, 'highWaterMark', opts.highWaterMark ); - setReadOnlyAccessor( malloc, 'nbytes', getBytes ); - - return malloc; - - /** - * Returns the number of allocated bytes. - * - * @private - * @returns {NonNegativeInteger} number of allocated bytes - */ - function getBytes() { - return nbytes; - } - - /** - * Returns an array buffer. - * - * @private - * @param {NonNegativeInteger} n - number of bytes - * @returns {(ArrayBuffer|null)} array buffer or null - */ - function arraybuffer( n ) { - var buf; - var i; - - // Convert the number of bytes to an index in our pool table: - i = log2( n ); - - // If we already have an available array buffer, use it... - if ( i < pool.length && pool[ i ].length ) { - return pool[ i ].pop(); - } - // Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate... - if ( nbytes+n > opts.highWaterMark ) { - return null; - } - buf = new ArrayBuffer( n ); - - // Update the running counter of allocated bytes: - nbytes += n; - - return buf; - } - - /** - * Returns a typed array. - * - * @private - * @param {Function} ctor - typed array constructor - * @param {NonNegativeInteger} len - view length - * @param {string} dtype - data type - * @returns {(TypedArray|null)} typed array or null - */ - function typedarray( ctor, len, dtype ) { - var buf; - if ( len === 0 ) { - return new ctor( 0 ); - } - buf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] ); - if ( buf === null ) { - return buf; - } - return new ctor( buf, 0, len ); - } - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length or an array-like object - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function malloc() { - var nargs; - var dtype; - var ctor; - var arr; - var out; - var set; - var get; - var len; - var i; - - nargs = arguments.length; - if ( nargs && isString( arguments[ nargs-1 ] ) ) { - nargs -= 1; - dtype = arguments[ nargs ]; - } else { - dtype = 'float64'; - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( '00d2k', dtype ) ); - } - if ( nargs <= 0 ) { - return new ctor( 0 ); - } - // Check if provided a typed array length... - if ( isNonNegativeInteger( arguments[ 0 ] ) ) { - return typedarray( ctor, arguments[ 0 ], dtype ); - } - // Check if provided an array-like object containing data elements... - if ( isCollection( arguments[ 0 ] ) ) { - arr = arguments[ 0 ]; - len = arr.length; - if ( isComplex128Array( arr ) ) { - arr = reinterpret128( arr, 0 ); - } else if ( isComplex64Array( arr ) ) { - arr = reinterpret64( arr, 0 ); - } else if ( /^complex/.test( dtype ) ) { - // Assume we've been provided an array of interleaved real and imaginary components... - len /= 2; - } - out = typedarray( ctor, len, dtype ); - if ( out === null ) { - return out; - } - if ( isCmplx128Array( out ) || isCmplx64Array( out ) ) { - out.set( arr ); - return out; - } - // Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other "unsafe" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things... - get = accessors( adtype( arr ) ).accessors[ 0 ]; - set = accessors( dtype ).accessors[ 1 ]; - for ( i = 0; i < len; i++ ) { - set( out, i, get( arr, i ) ); - } - return out; - } - throw new TypeError( format( '00d33', arguments[ 0 ] ) ); - } - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {NonNegativeInteger} [len=0] - array length - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function calloc() { - var nargs; - var out; - var tmp; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - out = malloc(); - } else if ( nargs === 1 ) { - out = malloc( arguments[ 0 ] ); - } else { - out = malloc( arguments[ 0 ], arguments[ 1 ] ); - } - if ( out !== null ) { - // Initialize the memory... - if ( isCmplx128Array( out ) ) { - tmp = reinterpret128( out, 0 ); - } else if ( isCmplx64Array( out ) ) { - tmp = reinterpret64( out, 0 ); - } else { - tmp = out; - } - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = 0.0; - } - } - return out; - } - - /** - * Frees a typed array or typed array buffer. - * - * ## Notes - * - * - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., "freeing" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool. - * - * @private - * @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free - * @throws {TypeError} must provide a typed array or typed array buffer - * @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed - */ - function free( buf ) { - var n; - var p; - var i; - if ( isTypedArrayLike( buf ) && buf.buffer ) { - buf = buf.buffer; - } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) ); - } - if ( buf.byteLength > 0 ) { - n = floor( log2( buf.byteLength ) ); - - // Prohibit "freeing" array buffers which would potentially allow users to circumvent high water mark limits: - n = min( pool.length-1, n ); - - // Ensure that we do not attempt to free the same buffer more than once... - p = pool[ n ]; - for ( i = 0; i < p.length; i++ ) { - if ( p[ i ] === buf ) { - return false; - } - } - // Add the buffer to our pool of free buffers: - p.push( buf ); - } - return true; - } - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @private - */ - function clear() { - var i; - for ( i = 0; i < pool.length; i++ ) { - pool[ i ].length = 0; - } - nbytes = 0; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6c12a4e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Typed array pool. -* -* @module @stdlib/array-pool -* -* @example -* var typedarraypool = require( '@stdlib/array-pool' ); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8f69ee3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,63 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @name typedarraypool -* @type {Function} -* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a valid array length or an array-like object -* @throws {TypeError} must provide a recognized data type -* @returns {(TypedArray|null)} typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -var typedarraypool = factory(); - - -// EXPORTS // - -module.exports = typedarraypool; diff --git a/lib/pool.js b/lib/pool.js deleted file mode 100644 index 5abd287..0000000 --- a/lib/pool.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Initializes a cache for pooled typed array buffers. -* -* @private -* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size -* @returns {ArrayArray} initialized cache -*/ -function pool( n ) { - var out; - var i; - - out = []; - for ( i = 0; i < n+1; i++ ) { - out.push( [] ); - } - return out; -} - - -// EXPORTS // - -module.exports = pool; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 4135ec9..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'highWaterMark': 1024 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '00d2h', options ) ); - } - if ( hasOwnProp( options, 'highWaterMark' ) ) { - opts.highWaterMark = options.highWaterMark; - if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( '00d35', 'highWaterMark', opts.highWaterMark ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 7d353bb..0399bd9 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Typed array pool.", "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,76 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessors": "^0.0.2", - "@stdlib/array-buffer": "^0.0.6", - "@stdlib/array-dtype": "^0.0.6", - "@stdlib/array-typed-ctors": "^0.0.6", - "@stdlib/assert-has-own-property": "^0.0.7", - "@stdlib/assert-is-arraybuffer": "^0.0.8", - "@stdlib/assert-is-collection": "^0.0.8", - "@stdlib/assert-is-complex128array": "^0.0.7", - "@stdlib/assert-is-complex64array": "^0.0.7", - "@stdlib/assert-is-nonnegative-integer": "^0.0.7", - "@stdlib/assert-is-plain-object": "^0.0.7", - "@stdlib/assert-is-string": "^0.0.8", - "@stdlib/assert-is-typed-array-like": "^0.0.8", - "@stdlib/math-base-special-ceil": "^0.0.8", - "@stdlib/math-base-special-ceil2": "^0.0.6", - "@stdlib/math-base-special-floor": "^0.0.8", - "@stdlib/math-base-special-log2": "^0.0.7", - "@stdlib/math-base-special-min": "^0.0.7", - "@stdlib/strided-base-reinterpret-complex128": "^0.0.2", - "@stdlib/strided-base-reinterpret-complex64": "^0.0.2", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.7", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.0.6", - "@stdlib/array-complex64": "^0.0.6", - "@stdlib/array-float32": "^0.0.6", - "@stdlib/array-float64": "^0.0.6", - "@stdlib/array-int16": "^0.0.6", - "@stdlib/array-int32": "^0.0.6", - "@stdlib/array-int8": "^0.0.6", - "@stdlib/array-uint16": "^0.0.6", - "@stdlib/array-uint32": "^0.0.6", - "@stdlib/array-uint8": "^0.0.7", - "@stdlib/array-uint8c": "^0.0.8", - "@stdlib/assert-instance-of": "^0.0.8", - "@stdlib/assert-is-complex-typed-array": "^0.0.6", - "@stdlib/assert-is-function": "^0.0.8", - "@stdlib/assert-is-typed-array": "^0.0.6", - "@stdlib/bench": "^0.0.12", - "@stdlib/complex-float32": "^0.0.7", - "@stdlib/complex-float64": "^0.0.8", - "@stdlib/complex-imag": "^0.0.7", - "@stdlib/complex-imagf": "^0.0.1", - "@stdlib/complex-real": "^0.0.7", - "@stdlib/complex-realf": "^0.0.1", - "@stdlib/math-base-special-pow": "^0.0.7", - "@stdlib/random-base-randu": "^0.0.8", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..954b2e0 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 396aee2..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,2240 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function (no options)', function test( t ) { - t.strictEqual( typeof factory(), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - t.strictEqual( typeof factory( {} ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided a `highWaterMark` option which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (length)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a function which returns a typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, length)', function test( t ) { - var typedarraypool = factory(); - var arr; - - arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a `malloc` method which is a circular reference', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - var buf; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the returned function is a property which returns the pool\'s high water mark', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function supports specifying a high water mark which limits the total amount of memory a pool can allocate', function test( t ) { - var typedarraypool; - var arr1; - var arr2; - - typedarraypool = factory({ - 'highWaterMark': 64 // bytes - }); - - typedarraypool.clear(); - - arr1 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr1.length, 8, 'returns expected value' ); - t.strictEqual( arr1.byteLength, 64, 'returns expected value' ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - typedarraypool.free( arr1 ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Create an array which is less than or equal to the high water mark: - arr2 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr2.length, 8, 'returns expected value' ); - t.strictEqual( arr2.byteLength, 64, 'returns expected value' ); - - typedarraypool.free( arr2 ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a property which returns the total number of accumulated bytes', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var typedarraypool; - var arrs; - var i; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 54aa5ee..0000000 --- a/test/test.js +++ /dev/null @@ -1,1797 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var typedarraypool = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -}); From 75ada0f361702b830547cb606b1dc0c323430377 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 19 Aug 2023 01:48:09 +0000 Subject: [PATCH 032/103] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index edfecbe..ae28056 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -34,7 +34,7 @@ var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); var accessors = require( '@stdlib/array-base-accessors' ); var adtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ArrayBuffer = require( '@stdlib/array-buffer' ); var ceil = require( '@stdlib/math-base-special-ceil' ); var floor = require( '@stdlib/math-base-special-floor' ); @@ -226,7 +226,7 @@ function factory( options ) { } ctor = ctors( dtype ); if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '01H2Y,KZ', dtype ) ); } if ( nargs <= 0 ) { return new ctor( 0 ); @@ -263,7 +263,7 @@ function factory( options ) { } return out; } - throw new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) ); + throw new TypeError( format( '01H2r,N0', arguments[ 0 ] ) ); } /** @@ -329,7 +329,7 @@ function factory( options ) { if ( isTypedArrayLike( buf ) && buf.buffer ) { buf = buf.buffer; } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) ); + throw new TypeError( format( '01H2s,N1', buf ) ); } if ( buf.byteLength > 0 ) { n = floor( log2( buf.byteLength ) ); diff --git a/lib/validate.js b/lib/validate.js index ce54890..95667c7 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '01H2V,FD', options ) ); } if ( hasOwnProp( options, 'highWaterMark' ) ) { opts.highWaterMark = options.highWaterMark; if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) ); + return new TypeError( format( '01H2t,G9', 'highWaterMark', opts.highWaterMark ) ); } } return null; diff --git a/package.json b/package.json index 5151fc3..7d353bb 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "@stdlib/math-base-special-min": "^0.0.7", "@stdlib/strided-base-reinterpret-complex128": "^0.0.2", "@stdlib/strided-base-reinterpret-complex64": "^0.0.2", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.7", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7" From 418e089b3fb17b4849671aa4e55edf483bafb39f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 19 Aug 2023 01:59:20 +0000 Subject: [PATCH 033/103] Remove files --- index.d.ts | 359 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6541 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 4500b91..0000000 --- a/index.d.ts +++ /dev/null @@ -1,359 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; -import ArrayBuffer = require( '@stdlib/array-buffer' ); - -/** -* Typed array or null. -*/ -type TypedArrayOrNull = RealOrComplexTypedArray | null; - -/** -* Interface defining pool options. -*/ -interface Options { - /** - * Maximum total memory which can be allocated. - */ - highWaterMark?: number; -} - -/** -* Pool interface. -*/ -interface Pool { - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr = typedarraypool(); - * // returns [] - * - * @example - * var arr = typedarraypool( 'float32' ); - * // returns [] - */ - ( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * // Allocate an array of doubles: - * var arr = typedarraypool( 5, 'float64' ); - * // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * typedarraypool.free( arr ); - * - * @example - * var arr1 = typedarraypool( [ 0.5, 0.5, 0.5 ] ); - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * @example - * var arr1 = [ 0.5, 0.5, 0.5 ]; - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - */ - ( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc(); - * // returns [] - * - * var arr2 = typedarraypool.calloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param length - typed array length - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc( 5 ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * var arr2 = typedarraypool.calloc( 5, 'uint8' ); - * // returns [ 0, 0, 0, 0, 0 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( length: number, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc(); - * // returns [] - * - * var arr2 = typedarraypool.malloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc( 5 ); - * // returns - * - * var arr2 = typedarraypool.malloc( 5, 'uint8' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 5.0, -3.0, 2.0 ] ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr2 = typedarraypool.malloc( arr1 ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr3 = typedarraypool.malloc( arr1, 'int32' ); - * // returns [ 5, -3, 2 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * typedarraypool.free( arr3 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ] ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * var arr2 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ], 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Frees a typed array or typed array buffer for use in a future allocation. - * - * @param buf - typed array or typed array buffer to free - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array for use in a future allocation: - * typedarraypool.free( arr ); - * - * // Create another typed array: - * arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array buffer for use in a future allocation: - * typedarraypool.free( arr.buffer ); - */ - free( buf: RealOrComplexTypedArray | ArrayBuffer ): void; - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr ); - * - * // ... - * - * // Clear all freed buffers: - * typedarraypool.clear(); - */ - clear(): void; - - /** - * Read-only property returning the pool's high water mark. - * - * ## Notes - * - * - Once a high water mark is reached, typed array allocation fails. - * - * @example - * var limit = typedarraypool.highWaterMark; - * // returns - */ - readonly highWaterMark: number; - - /** - * Read-only property returning the total number of allocated bytes. - * - * @example - * var arr = typedarraypool( 5, 'float64' ); - * - * var nbytes = typedarraypool.nbytes; - * // returns - */ - readonly nbytes: number; - - /** - * Creates a typed array pool. - * - * @param options - pool options - * @param options.highWaterMark - maximum total memory which can be allocated - * @throws must provide valid options - * @returns allocator - * - * @example - * var allocator = typedarraypool.factory(); - * - * // Allocate an array of doubles: - * var arr = allocator( 5, 'float64' ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * allocator.free( arr ); - */ - factory( options?: Options ): Pool; -} - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @param arg - an array length or an array-like object -* @param dtype - data type (default: 'float64') -* @returns typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -declare var typedarraypool: Pool; - - -// EXPORTS // - -export = typedarraypool; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 379878d..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessors@v0.0.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.0.7-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";function k(e,t){return y(t)?w(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(c("00d35","highWaterMark",e.highWaterMark)):null:new TypeError(c("00d2h",t))}function M(e){var t,r;for(t=[],r=0;rT.highWaterMark?null:(t=new j(e),w+=e,t)}function q(e,t,r){var s;return 0===t?new e(0):null===(s=V(b(t)*W[r]))?s:new e(s,0,t)}function z(){var e,i,n,d,j,g,u,b,v;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(n=l(i)))throw new TypeError(c("00d2k",i));if(e<=0)return new n(0);if(r(arguments[0]))return q(n,arguments[0],i);if(s(arguments[0])){if(b=(d=arguments[0]).length,m(d)?d=h(d,0):o(d)?d=a(d,0):/^complex/.test(i)&&(b/=2),null===(j=q(n,b,i)))return j;if(A(j)||L(j))return j.set(d),j;for(u=p(f(d)).accessors[0],g=p(i).accessors[1],v=0;v0){for(t=u(v(e.byteLength)),t=x(E.length-1,t),r=E[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '00d2k', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = accessors( adtype( arr ) ).accessors[ 0 ];\n\t\t\tset = accessors( dtype ).accessors[ 1 ];\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '00d33', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","accessors","adtype","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;6nEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,QAAS,gBAAiBP,EAAKI,gBAGxD,KARC,IAAIE,UAAWC,EAAQ,QAASN,GASzC,CC/BA,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,iHCaIG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EC/EO,CACNI,cAAiB,kBD+EbkB,UAAUC,SACdF,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOgB,EAAYC,EAAMC,EAAM1B,EAAKI,iBACpCgB,EAAS,EAETO,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB5B,EAAKI,eAC3C4B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOb,CACP,CASD,SAASc,EAAazB,GACrB,IAAI0B,EACAxB,EAMJ,OAHAA,EAAIe,EAAMjB,IAGDD,EAAKe,QAAUf,EAAMG,GAAIY,OAC1Bf,EAAMG,GAAIyB,MAGbhB,EAAOX,EAAIT,EAAKI,cACb,MAER+B,EAAM,IAAIE,EAAa5B,GAGvBW,GAAUX,EAEH0B,EACP,CAWD,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,EACzB,CAkBD,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAtB,EACAP,EACAmC,EACAC,EACAN,EACA7B,EAUJ,GALC8B,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAOzB,EAAO2B,IAEb,MAAM,IAAInC,UAAWC,EAAQ,QAASkC,IAEvC,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKlC,EAAsBiB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAvB,EAAMK,UAAW,IACPC,OACL0B,EAAmBhC,GACvBA,EAAMiC,EAAgBjC,EAAK,GAChBkC,EAAkBlC,GAC7BA,EAAMmC,EAAenC,EAAK,GACf,WAAWoC,KAAMZ,KAE5BD,GAAO,GAGK,QADb9B,EAAM4B,EAAYC,EAAMC,EAAKC,IAE5B,OAAO/B,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAImC,IAAK5B,GACFP,EAKR,IAFAoC,EAAMQ,EAAWC,EAAQtC,IAAQqC,UAAW,GAC5CT,EAAMS,EAAWb,GAAQa,UAAW,GAC9B3C,EAAI,EAAGA,EAAI6B,EAAK7B,IACrBkC,EAAKnC,EAAKC,EAAGmC,EAAK7B,EAAKN,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,QAASe,UAAW,IACjD,CAgBD,SAASO,IACR,IAAIe,EACAlC,EACA8C,EACA7C,EAUJ,GAAa,QANZD,EADc,KADfkC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCkC,EADItC,EAAiBR,GACfwC,EAAgBxC,EAAK,GAChBM,EAAgBN,GACrB0C,EAAe1C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAI6C,EAAIjC,OAAQZ,IAC5B6C,EAAK7C,GAAM,EAGb,OAAOD,CACP,CAcD,SAASoB,EAAMK,GACd,IAAI1B,EACAgD,EACA9C,EACJ,GAAK+C,EAAkBvB,IAASA,EAAIwB,OACnCxB,EAAMA,EAAIwB,YACJ,IAAMC,EAAezB,GAC3B,MAAM,IAAI7B,UAAWC,EAAQ,4EAA6E4B,IAE3G,GAAKA,EAAI0B,WAAa,EAAI,CAQzB,IAPApD,EAAIqD,EAAOpC,EAAMS,EAAI0B,aAGrBpD,EAAIsD,EAAKvD,EAAKe,OAAO,EAAGd,GAGxBgD,EAAIjD,EAAMC,GACJE,EAAI,EAAGA,EAAI8C,EAAElC,OAAQZ,IAC1B,GAAK8C,EAAG9C,KAAQwB,EACf,OAAO,EAITsB,EAAE7C,KAAMuB,EACR,CACD,OAAO,CACP,CAOD,SAASJ,IACR,IAAIpB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKe,OAAQZ,IAC7BH,EAAMG,GAAIY,OAAS,EAEpBH,EAAS,CACT,CACF,CEnTG,IAAC4C,EAAiB7C,ICPrBQ,EAAAsC,EAAA,UAAA9C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 954b2e0..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f087a474b43c8fad284dcbddb19f140793b9d28d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 19 Aug 2023 02:00:43 +0000 Subject: [PATCH 034/103] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 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 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- benchmark/benchmark.calloc.js | 246 - benchmark/benchmark.factory.js | 71 - benchmark/benchmark.js | 246 - benchmark/benchmark.length.complex128.js | 102 - benchmark/benchmark.length.complex64.js | 102 - benchmark/benchmark.length.float32.js | 102 - benchmark/benchmark.length.float64.js | 102 - benchmark/benchmark.length.int16.js | 102 - benchmark/benchmark.length.int32.js | 102 - benchmark/benchmark.length.int8.js | 102 - benchmark/benchmark.length.uint16.js | 102 - benchmark/benchmark.length.uint32.js | 102 - benchmark/benchmark.length.uint8.js | 102 - benchmark/benchmark.length.uint8c.js | 102 - benchmark/benchmark.malloc.js | 246 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 347 -- docs/types/test.ts | 193 - examples/index.js | 80 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/bytes_per_element.json | 13 - lib/defaults.js | 42 - lib/factory.js | 370 -- lib/index.js | 56 - lib/main.js | 63 - lib/pool.js | 44 - lib/validate.js | 66 - package.json | 97 +- stats.html | 6177 +++++++++++++++++++++ test/test.factory.js | 2240 -------- test/test.js | 1797 ------ 59 files changed, 6206 insertions(+), 10503 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.calloc.js delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.complex128.js delete mode 100644 benchmark/benchmark.length.complex64.js delete mode 100644 benchmark/benchmark.length.float32.js delete mode 100644 benchmark/benchmark.length.float64.js delete mode 100644 benchmark/benchmark.length.int16.js delete mode 100644 benchmark/benchmark.length.int32.js delete mode 100644 benchmark/benchmark.length.int8.js delete mode 100644 benchmark/benchmark.length.uint16.js delete mode 100644 benchmark/benchmark.length.uint32.js delete mode 100644 benchmark/benchmark.length.uint8.js delete mode 100644 benchmark/benchmark.length.uint8c.js delete mode 100644 benchmark/benchmark.malloc.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/bytes_per_element.json delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/pool.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ea35f20..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/array/pool) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 fc6d38a..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/array/pool) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 9ef1395..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 91f2b93..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,783 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -482,7 +481,7 @@ console.log( 'nbytes: %d', typedarray.nbytes ); ## 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]. @@ -548,7 +547,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm diff --git a/benchmark/benchmark.calloc.js b/benchmark/benchmark.calloc.js deleted file mode 100644 index e5a1c77..0000000 --- a/benchmark/benchmark.calloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':calloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index f7cd676..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = typedarray.factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:highWaterMark', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'highWaterMark': 0 - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.highWaterMark = i; - f = typedarray.factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a023d2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.complex128.js b/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 47b623b..0000000 --- a/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex64.js b/benchmark/benchmark.length.complex64.js deleted file mode 100644 index 40a412b..0000000 --- a/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float32.js b/benchmark/benchmark.length.float32.js deleted file mode 100644 index 0227ed7..0000000 --- a/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float64.js b/benchmark/benchmark.length.float64.js deleted file mode 100644 index 2dbac1c..0000000 --- a/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int16.js b/benchmark/benchmark.length.int16.js deleted file mode 100644 index e2a8adc..0000000 --- a/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int32.js b/benchmark/benchmark.length.int32.js deleted file mode 100644 index e4df0aa..0000000 --- a/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int8.js b/benchmark/benchmark.length.int8.js deleted file mode 100644 index 7ceac11..0000000 --- a/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint16.js b/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 9a532b6..0000000 --- a/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint32.js b/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 98f2d7f..0000000 --- a/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8.js b/benchmark/benchmark.length.uint8.js deleted file mode 100644 index 8359249..0000000 --- a/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8c.js b/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index d47d023..0000000 --- a/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.malloc.js b/benchmark/benchmark.malloc.js deleted file mode 100644 index d4eea72..0000000 --- a/benchmark/benchmark.malloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':malloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 9689761..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/array/pool" -%% click B href "https://github.com/stdlib-js/array-pool/tree/main" -%% click C href "https://github.com/stdlib-js/array-pool/tree/production" -%% click D href "https://github.com/stdlib-js/array-pool/tree/esm" -%% click E href "https://github.com/stdlib-js/array-pool/tree/deno" -%% click F href "https://github.com/stdlib-js/array-pool/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/pool -[production-url]: https://github.com/stdlib-js/array-pool/tree/production -[deno-url]: https://github.com/stdlib-js/array-pool/tree/deno -[umd-url]: https://github.com/stdlib-js/array-pool/tree/umd -[esm-url]: https://github.com/stdlib-js/array-pool/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 5160b6f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import typedarraypool from '../docs/types/index'; -export = typedarraypool; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 9d31d69..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var l=function(n,i){return function(){return i||n((i={exports:{}}).exports,i),i.exports}};var k=l(function(kr,M){ -function D(){return{highWaterMark:9007199254740992}}M.exports=D -});var E=l(function(Ar,W){ -var G=require('@stdlib/assert-is-plain-object/dist'),H=require('@stdlib/assert-has-own-property/dist'),J=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,A=require('@stdlib/error-tools-fmtprodmsg/dist');function K(n,i){return G(i)?H(i,"highWaterMark")&&(n.highWaterMark=i.highWaterMark,!J(n.highWaterMark))?new TypeError(A('01H2t',"highWaterMark",n.highWaterMark)):null:new TypeError(A('01H2V',i));}W.exports=K -});var C=l(function(Wr,T){ -function Q(n){var i,u;for(i=[],u=0;uv.highWaterMark?null:(e=new ur(r),i+=r,e)}function d(r,e,t){var a;return e===0?new r(0):(a=_(lr(e)*hr[t]),a===null?a:new r(a,0,e))}function s(){var r,e,t,a,o,x,w,c,f;if(r=arguments.length,r&&X(arguments[r-1])?(r-=1,e=arguments[r]):e="float64",t=y(e),t===null)throw new TypeError(m('01H2Y',e));if(r<=0)return new t(0);if(Z(arguments[0]))return d(t,arguments[0],e);if($(arguments[0])){if(a=arguments[0],c=a.length,tr(a)?a=P(a,0):ar(a)?a=b(a,0):/^complex/.test(e)&&(c/=2),o=d(t,c,e),o===null)return o;if(L(o)||N(o))return o.set(a),o;for(w=B(nr(a)).accessors[0],x=B(e).accessors[1],f=0;f0){for(e=or(p(r.byteLength)),e=vr(u.length-1,e),t=u[e],a=0;a[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = accessors( adtype( arr ) ).accessors[ 0 ];\n\t\t\tset = accessors( dtype ).accessors[ 1 ];\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nmodule.exports = typedarraypool;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* var typedarraypool = require( '@stdlib/array-pool' );\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,cAAiB,gBAClB,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,eAAgB,IACzCD,EAAK,cAAgBC,EAAQ,cACxB,CAACJ,EAAsBG,EAAK,aAAc,GACvC,IAAI,UAAWF,EAAQ,2EAA4E,gBAAiBE,EAAK,aAAc,CAAE,EAG3I,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cA6BA,SAASC,EAAM,EAAI,CAClB,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAI,EAAE,EAAGA,IACrBD,EAAI,KAAM,CAAC,CAAE,EAEd,OAAOA,CACR,CAKAF,EAAO,QAAUC,IC3CjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,QAAW,EACX,QAAW,EACX,MAAS,EACT,MAAS,EACT,KAAQ,EACR,OAAU,EACV,OAAU,EACV,MAAS,EACT,OAAU,EACT,UAAa,EACb,WAAc,EAChB,ICZA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAe,QAAS,8BAA+B,EACvDC,GAAmB,QAAS,oCAAqC,EACjEC,GAAgB,QAAS,+BAAgC,EACzDC,GAAmB,QAAS,kCAAmC,EAC/DC,GAAoB,QAAS,mCAAoC,EACjEC,EAAc,QAAS,uDAAwD,EAC/EC,GAAsB,QAAS,uDAAwD,EACvFC,EAAQ,QAAS,2BAA4B,EAC7CC,EAAgB,QAAS,4CAA6C,EACtEC,EAAiB,QAAS,6CAA8C,EACxEC,EAAY,QAAS,8BAA+B,EACpDC,GAAS,QAAS,qBAAsB,EACxCC,EAAS,QAAS,uBAAwB,EAC1CC,GAAc,QAAS,sBAAuB,EAC9CC,GAAO,QAAS,gCAAiC,EACjDC,GAAQ,QAAS,iCAAkC,EACnDC,GAAQ,QAAS,iCAAkC,EACnDC,EAAO,QAAS,gCAAiC,EACjDC,GAAM,QAAS,+BAAgC,EAC/CC,GAAW,IACXC,GAAW,IACXC,GAAa,IACbC,GAAoB,IAKpBC,GAAiBhB,EAAO,WAAY,EACpCiB,GAAkBjB,EAAO,YAAa,EAY1C,SAASkB,EAAgBC,EAAM,CAC9B,OAASA,aAAeH,EACzB,CASA,SAASI,EAAiBD,EAAM,CAC/B,OAASA,aAAeF,EACzB,CA6BA,SAASI,GAASC,EAAU,CAC3B,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,EAAOb,GAAS,EACX,UAAU,SACdc,EAAMb,GAAUY,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAAF,EAAOV,GAAYP,GAAMG,EAAMe,EAAK,aAAc,CAAE,CAAE,EACtDF,EAAS,EAETzB,EAAa6B,EAAQ,SAAUA,CAAO,EACtC7B,EAAa6B,EAAQ,SAAUC,CAAO,EACtC9B,EAAa6B,EAAQ,OAAQE,CAAK,EAClC/B,EAAa6B,EAAQ,QAASG,CAAM,EACpChC,EAAa6B,EAAQ,gBAAiBF,EAAK,aAAc,EACzD1B,GAAqB4B,EAAQ,SAAUI,CAAS,EAEzCJ,EAQP,SAASI,GAAW,CACnB,OAAOR,CACR,CASA,SAASS,EAAaC,EAAI,CACzB,IAAIC,EACAC,EAMJ,OAHAA,EAAIzB,EAAMuB,CAAE,EAGPE,EAAIX,EAAK,QAAUA,EAAMW,CAAE,EAAE,OAC1BX,EAAMW,CAAE,EAAE,IAAI,EAGjBZ,EAAOU,EAAIR,EAAK,cACb,MAERS,EAAM,IAAI5B,GAAa2B,CAAE,EAGzBV,GAAUU,EAEHC,EACR,CAWA,SAASE,EAAYC,EAAMC,EAAKC,EAAQ,CACvC,IAAIL,EACJ,OAAKI,IAAQ,EACL,IAAID,EAAM,CAAE,GAEpBH,EAAMF,EAAavB,GAAO6B,CAAI,EAAEvB,GAAmBwB,CAAM,CAAE,EACtDL,IAAQ,KACLA,EAED,IAAIG,EAAMH,EAAK,EAAGI,CAAI,EAC9B,CAkBA,SAASX,GAAS,CACjB,IAAIa,EACAD,EACAF,EACAlB,EACAsB,EACAC,EACAC,EACAL,EACAH,EAUJ,GARAK,EAAQ,UAAU,OACbA,GAASjD,EAAU,UAAWiD,EAAM,CAAE,CAAE,GAC5CA,GAAS,EACTD,EAAQ,UAAWC,CAAM,GAEzBD,EAAQ,UAETF,EAAOrC,EAAOuC,CAAM,EACfF,IAAS,KACb,MAAM,IAAI,UAAWhC,EAAQ,sEAAuEkC,CAAM,CAAE,EAE7G,GAAKC,GAAS,EACb,OAAO,IAAIH,EAAM,CAAE,EAGpB,GAAK7C,EAAsB,UAAW,CAAE,CAAE,EACzC,OAAO4C,EAAYC,EAAM,UAAW,CAAE,EAAGE,CAAM,EAGhD,GAAK9C,EAAc,UAAW,CAAE,CAAE,EAAI,CAYrC,GAXA0B,EAAM,UAAW,CAAE,EACnBmB,EAAMnB,EAAI,OACLtB,GAAmBsB,CAAI,EAC3BA,EAAMjB,EAAgBiB,EAAK,CAAE,EAClBvB,GAAkBuB,CAAI,EACjCA,EAAMlB,EAAekB,EAAK,CAAE,EACjB,WAAW,KAAMoB,CAAM,IAElCD,GAAO,GAERG,EAAML,EAAYC,EAAMC,EAAKC,CAAM,EAC9BE,IAAQ,KACZ,OAAOA,EAER,GAAKrB,EAAiBqB,CAAI,GAAKvB,EAAgBuB,CAAI,EAClD,OAAAA,EAAI,IAAKtB,CAAI,EACNsB,EAKR,IAFAE,EAAMxC,EAAWC,GAAQe,CAAI,CAAE,EAAE,UAAW,CAAE,EAC9CuB,EAAMvC,EAAWoC,CAAM,EAAE,UAAW,CAAE,EAChCJ,EAAI,EAAGA,EAAIG,EAAKH,IACrBO,EAAKD,EAAKN,EAAGQ,EAAKxB,EAAKgB,CAAE,CAAE,EAE5B,OAAOM,CACR,CACA,MAAM,IAAI,UAAWpC,EAAQ,wGAAyG,UAAW,CAAE,CAAE,CAAE,CACxJ,CAgBA,SAASuB,GAAS,CACjB,IAAIY,EACAC,EACAG,EACAT,EAUJ,GARAK,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAMd,EAAO,EACFa,IAAU,EACrBC,EAAMd,EAAQ,UAAW,CAAE,CAAE,EAE7Bc,EAAMd,EAAQ,UAAW,CAAE,EAAG,UAAW,CAAE,CAAE,EAEzCc,IAAQ,KASZ,IAPKrB,EAAiBqB,CAAI,EACzBG,EAAM1C,EAAgBuC,EAAK,CAAE,EAClBvB,EAAgBuB,CAAI,EAC/BG,EAAM3C,EAAewC,EAAK,CAAE,EAE5BG,EAAMH,EAEDN,EAAI,EAAGA,EAAIS,EAAI,OAAQT,IAC5BS,EAAKT,CAAE,EAAI,EAGb,OAAOM,CACR,CAcA,SAASZ,EAAMK,EAAM,CACpB,IAAID,EACAY,EACAV,EACJ,GAAKzC,GAAkBwC,CAAI,GAAKA,EAAI,OACnCA,EAAMA,EAAI,eACC,CAACvC,GAAeuC,CAAI,EAC/B,MAAM,IAAI,UAAW7B,EAAQ,4EAA6E6B,CAAI,CAAE,EAEjH,GAAKA,EAAI,WAAa,EAAI,CAQzB,IAPAD,EAAIzB,GAAOE,EAAMwB,EAAI,UAAW,CAAE,EAGlCD,EAAItB,GAAKa,EAAK,OAAO,EAAGS,CAAE,EAG1BY,EAAIrB,EAAMS,CAAE,EACNE,EAAI,EAAGA,EAAIU,EAAE,OAAQV,IAC1B,GAAKU,EAAGV,CAAE,IAAMD,EACf,MAAO,GAITW,EAAE,KAAMX,CAAI,CACb,CACA,MAAO,EACR,CAOA,SAASJ,GAAQ,CAChB,IAAIK,EACJ,IAAMA,EAAI,EAAGA,EAAIX,EAAK,OAAQW,IAC7BX,EAAMW,CAAE,EAAE,OAAS,EAEpBZ,EAAS,CACV,CACD,CAKAjC,EAAO,QAAU+B,KCjXjB,IAAAyB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAU,IAmCVC,GAAiBD,GAAQ,EAK7BD,EAAO,QAAUE,KCnBjB,IAAIC,GAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,GAAU,IAKdF,GAAaC,EAAM,UAAWC,EAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isNonNegativeInteger", "format", "validate", "opts", "options", "require_pool", "__commonJSMin", "exports", "module", "pool", "out", "i", "require_bytes_per_element", "__commonJSMin", "exports", "module", "require_factory", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isCollection", "isTypedArrayLike", "isArrayBuffer", "isComplex64Array", "isComplex128Array", "setReadOnly", "setReadOnlyAccessor", "ctors", "reinterpret64", "reinterpret128", "accessors", "adtype", "format", "ArrayBuffer", "ceil", "floor", "ceil2", "log2", "min", "defaults", "validate", "createPool", "BYTES_PER_ELEMENT", "Complex64Array", "Complex128Array", "isCmplx64Array", "arr", "isCmplx128Array", "factory", "options", "nbytes", "pool", "opts", "err", "malloc", "calloc", "free", "clear", "getBytes", "arraybuffer", "n", "buf", "i", "typedarray", "ctor", "len", "dtype", "nargs", "out", "set", "get", "tmp", "p", "require_main", "__commonJSMin", "exports", "module", "factory", "typedarraypool", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5244595..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,347 +0,0 @@ - -{{alias}}( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - Memory is **uninitialized**, which means that the contents of a returned - typed array may contain sensitive contents. - - The function supports the following data types: - - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - The default typed array data type is `float64`. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}() - [] - > arr = {{alias}}( 'float32' ) - [] - - -{{alias}}( length[, dtype] ) - Returns an uninitialized typed array having a specified length from a typed - array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > arr = {{alias}}( 5, 'int32' ) - - - -{{alias}}( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - This method shares the same security vulnerabilities mentioned above. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc() - - > arr = {{alias}}.malloc( 'float32' ) - - - -{{alias}}.malloc( length[, dtype] ) - Returns a typed array having a specified length from a typed array memory - pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc( 5 ) - - > arr = {{alias}}.malloc( 5, 'int32' ) - - - -{{alias}}.malloc( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}.malloc( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.calloc( [dtype] ) - Returns a zero-initialized typed array from a typed array memory pool. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc() - [] - > arr = {{alias}}.calloc( 'float32' ) - [] - - -{{alias}}.calloc( length[, dtype] ) - Returns a zero-initialized typed array having a specified length from a - typed array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}.calloc( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}.free( buf ) - Frees a typed array or typed array buffer for use in a future allocation. - - Parameters - ---------- - buf: TypedArray|ArrayBuffer - Typed array or typed array buffer to free. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ) - - -{{alias}}.clear() - Clears the typed array pool allowing garbage collection of previously - allocated (and currently free) array buffers. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - > {{alias}}.clear() - - -{{alias}}.highWaterMark - Read-only property returning the pool's high water mark. - - Once a high water mark is reached, typed array allocation fails. - - Examples - -------- - > {{alias}}.highWaterMark - - -{{alias}}.nbytes - Read-only property returning the total number of allocated bytes. - - The returned value is the total accumulated value. Hence, anytime a pool - must allocate a new array buffer (i.e., more memory), the pool increments - this value. - - The only time this value is decremented is when a pool is cleared. - - This behavior means that, while allocated buffers which are never freed may, - in fact, be garbage collected, they continue to count against the high water - mark limit. - - Accordingly, you should *always* free allocated buffers in order to prevent - the pool from believing that non-freed buffers are continually in use. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.nbytes - - -{{alias}}.factory( [options] ) - Creates a typed array pool. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.highWaterMark: integer (optional) - Maximum total memory (in bytes) which can be allocated. - - Returns - ------- - fcn: Function - Function for creating typed arrays from a typed array memory pool. - - Examples - -------- - > var pool = {{alias}}.factory(); - > var arr1 = pool( 3, 'float64' ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1014bba..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,193 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-empty */ -/* tslint:disable:no-unused-expression */ - -import typedarraypool = require( './index' ); - - -// TESTS // - -// The function returns a typed array or null... -{ - typedarraypool(); // $ExpectType TypedArrayOrNull - typedarraypool( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the function is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool( true ); // $ExpectError - typedarraypool( false ); // $ExpectError - typedarraypool( null ); // $ExpectError - typedarraypool( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized data type... -{ - typedarraypool( 4, true ); // $ExpectError - typedarraypool( 4, false ); // $ExpectError - typedarraypool( 4, null ); // $ExpectError - typedarraypool( 4, 'abc' ); // $ExpectError - typedarraypool( 4, 123 ); // $ExpectError - typedarraypool( 4, [] ); // $ExpectError - typedarraypool( 4, {} ); // $ExpectError - typedarraypool( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an incorrect number of arguments... -{ - typedarraypool( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `malloc` method which returns a typed array or null... -{ - typedarraypool.malloc(); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.malloc( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `malloc` method is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool.malloc( true ); // $ExpectError - typedarraypool.malloc( false ); // $ExpectError - typedarraypool.malloc( null ); // $ExpectError - typedarraypool.malloc( {} ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.malloc( 4, true ); // $ExpectError - typedarraypool.malloc( 4, false ); // $ExpectError - typedarraypool.malloc( 4, null ); // $ExpectError - typedarraypool.malloc( 4, 'abc' ); // $ExpectError - typedarraypool.malloc( 4, 123 ); // $ExpectError - typedarraypool.malloc( 4, [] ); // $ExpectError - typedarraypool.malloc( 4, {} ); // $ExpectError - typedarraypool.malloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided an incorrect number of arguments... -{ - typedarraypool.malloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `calloc` method which returns a typed array or null... -{ - typedarraypool.calloc(); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `calloc` method is provided a first argument which is not a number... -{ - typedarraypool.calloc( 'abc' ); // $ExpectError - typedarraypool.calloc( true ); // $ExpectError - typedarraypool.calloc( false ); // $ExpectError - typedarraypool.calloc( null ); // $ExpectError - typedarraypool.calloc( {} ); // $ExpectError - typedarraypool.calloc( [] ); // $ExpectError - typedarraypool.calloc( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.calloc( 4, true ); // $ExpectError - typedarraypool.calloc( 4, false ); // $ExpectError - typedarraypool.calloc( 4, null ); // $ExpectError - typedarraypool.calloc( 4, 'abc' ); // $ExpectError - typedarraypool.calloc( 4, 123 ); // $ExpectError - typedarraypool.calloc( 4, [] ); // $ExpectError - typedarraypool.calloc( 4, {} ); // $ExpectError - typedarraypool.calloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided an incorrect number of arguments... -{ - typedarraypool.calloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `factory` method which returns a typed array pool.. -{ - typedarraypool.factory(); // $ExpectType Pool - typedarraypool.factory( { 'highWaterMark': 556 } ); // $ExpectType Pool -} - -// The compiler throws an error if the `factory` method is provided a `highWaterMark` option which is not a number... -{ - typedarraypool.factory( { 'highWaterMark': true } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': false } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': 'abc' } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': null } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': [] } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': {} } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an incorrect number of arguments... -{ - typedarraypool.factory( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` method which returns void... -{ - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.free( arr ); // $ExpectType void -} - -// The compiler throws an error if the `free` method is provided a first argument which is neither a typed array nor array buffer... -{ - typedarraypool.free( true ); // $ExpectError - typedarraypool.free( false ); // $ExpectError - typedarraypool.free( 123 ); // $ExpectError - typedarraypool.free( 'abc' ); // $ExpectError - typedarraypool.free( null ); // $ExpectError - typedarraypool.free( {} ); // $ExpectError - typedarraypool.free( ( x: number ): number => x ); // $ExpectError -} - -// Attached to the main export is a `clear` method which returns void... -{ - typedarraypool.clear(); // $ExpectType void -} - -// The compiler throws an error if the `clear` method is provided arguments... -{ - typedarraypool.clear( {} ); // $ExpectError - typedarraypool.clear( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `highWaterMark` property... -{ - typedarraypool.highWaterMark; // $ExpectType number -} - -// Attached to the main export is a `nbytes` property... -{ - typedarraypool.nbytes; // $ExpectType number -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 24a7846..0000000 --- a/examples/index.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 randu = require( '@stdlib/random-base-randu' ); -var typedarraypool = require( './../lib' ); - -// Create a typed array pool which can allocate at most 1GB: -var typedarray = typedarraypool.factory({ - 'highWaterMark': 1e9 -}); - -// Inspect the pool: -console.log( 'Max bytes: %d', typedarray.highWaterMark ); -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Allocate an array for storing double-precision floating-point numbers: -var arr1 = typedarray( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Fill the array... -var i; -for ( i = 0; i < arr1.length; i++ ) { - arr1[ i ] = randu(); -} - -// Inspect array contents: -console.log( arr1 ); - -// Free the array: -typedarray.free( arr1 ); - -// Allocate another array similar to the previous one: -var arr2 = typedarray( 5, 'float64' ); -// returns - -// Check that we have been returned a new typed array view: -console.log( arr2 === arr1 ); -// => false - -// Inspect array contents: -console.log( arr2 ); - -// Free the array: -typedarray.free( arr2 ); - -// Allocate an initialized array: -var arr3 = typedarray.calloc( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect array contents: -console.log( arr3 ); - -// Free the array: -typedarray.free( arr3 ); - -// Clear the pool: -typedarray.clear(); - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index de70cb0..c6a3785 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; import ArrayBuffer = require( '@stdlib/array-buffer' ); diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..284e557 --- /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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessors@v0.0.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.0.7-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";function k(e,t){return y(t)?w(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(c("01H2t,G9","highWaterMark",e.highWaterMark)):null:new TypeError(c("01H2V,FD",t))}function M(e){var t,r;for(t=[],r=0;rH.highWaterMark?null:(t=new j(e),w+=e,t)}function G(e,t,r){var s;return 0===t?new e(0):null===(s=F(b(t)*W[r]))?s:new e(s,0,t)}function K(){var e,i,n,l,j,g,u,b,v;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(n=d(i)))throw new TypeError(c("01H2Y,KZ",i));if(e<=0)return new n(0);if(r(arguments[0]))return G(n,arguments[0],i);if(s(arguments[0])){if(b=(l=arguments[0]).length,m(l)?l=h(l,0):o(l)?l=a(l,0):/^complex/.test(i)&&(b/=2),null===(j=G(n,b,i)))return j;if(L(j)||T(j))return j.set(l),j;for(u=p(f(l)).accessors[0],g=p(i).accessors[1],v=0;v0){for(t=u(v(e.byteLength)),t=x(E.length-1,t),r=E[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '01H2Y,KZ', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = accessors( adtype( arr ) ).accessors[ 0 ];\n\t\t\tset = accessors( dtype ).accessors[ 1 ];\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '01H2r,N0', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( '01H2s,N1', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","accessors","adtype","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;6nEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,WAAY,gBAAiBP,EAAKI,gBAG3D,KARC,IAAIE,UAAWC,EAAQ,WAAYN,GAS5C,CC/BA,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,iHCaIG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EC/EO,CACNI,cAAiB,kBD+EbkB,UAAUC,SACdF,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOgB,EAAYC,EAAMC,EAAM1B,EAAKI,iBACpCgB,EAAS,EAETO,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB5B,EAAKI,eAC3C4B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOb,CACP,CASD,SAASc,EAAazB,GACrB,IAAI0B,EACAxB,EAMJ,OAHAA,EAAIe,EAAMjB,IAGDD,EAAKe,QAAUf,EAAMG,GAAIY,OAC1Bf,EAAMG,GAAIyB,MAGbhB,EAAOX,EAAIT,EAAKI,cACb,MAER+B,EAAM,IAAIE,EAAa5B,GAGvBW,GAAUX,EAEH0B,EACP,CAWD,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,EACzB,CAkBD,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAtB,EACAP,EACAmC,EACAC,EACAN,EACA7B,EAUJ,GALC8B,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAOzB,EAAO2B,IAEb,MAAM,IAAInC,UAAWC,EAAQ,WAAYkC,IAE1C,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKlC,EAAsBiB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAvB,EAAMK,UAAW,IACPC,OACL0B,EAAmBhC,GACvBA,EAAMiC,EAAgBjC,EAAK,GAChBkC,EAAkBlC,GAC7BA,EAAMmC,EAAenC,EAAK,GACf,WAAWoC,KAAMZ,KAE5BD,GAAO,GAGK,QADb9B,EAAM4B,EAAYC,EAAMC,EAAKC,IAE5B,OAAO/B,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAImC,IAAK5B,GACFP,EAKR,IAFAoC,EAAMQ,EAAWC,EAAQtC,IAAQqC,UAAW,GAC5CT,EAAMS,EAAWb,GAAQa,UAAW,GAC9B3C,EAAI,EAAGA,EAAI6B,EAAK7B,IACrBkC,EAAKnC,EAAKC,EAAGmC,EAAK7B,EAAKN,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,WAAYe,UAAW,IACpD,CAgBD,SAASO,IACR,IAAIe,EACAlC,EACA8C,EACA7C,EAUJ,GAAa,QANZD,EADc,KADfkC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCkC,EADItC,EAAiBR,GACfwC,EAAgBxC,EAAK,GAChBM,EAAgBN,GACrB0C,EAAe1C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAI6C,EAAIjC,OAAQZ,IAC5B6C,EAAK7C,GAAM,EAGb,OAAOD,CACP,CAcD,SAASoB,EAAMK,GACd,IAAI1B,EACAgD,EACA9C,EACJ,GAAK+C,EAAkBvB,IAASA,EAAIwB,OACnCxB,EAAMA,EAAIwB,YACJ,IAAMC,EAAezB,GAC3B,MAAM,IAAI7B,UAAWC,EAAQ,WAAY4B,IAE1C,GAAKA,EAAI0B,WAAa,EAAI,CAQzB,IAPApD,EAAIqD,EAAOpC,EAAMS,EAAI0B,aAGrBpD,EAAIsD,EAAKvD,EAAKe,OAAO,EAAGd,GAGxBgD,EAAIjD,EAAMC,GACJE,EAAI,EAAGA,EAAI8C,EAAElC,OAAQZ,IAC1B,GAAK8C,EAAG9C,KAAQwB,EACf,OAAO,EAITsB,EAAE7C,KAAMuB,EACR,CACD,OAAO,CACP,CAOD,SAASJ,IACR,IAAIpB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKe,OAAQZ,IAC7BH,EAAMG,GAAIY,OAAS,EAEpBH,EAAS,CACT,CACF,CEnTG,IAAC4C,EAAiB7C,ICPrBQ,EAAAsC,EAAA,UAAA9C"} \ No newline at end of file diff --git a/lib/bytes_per_element.json b/lib/bytes_per_element.json deleted file mode 100644 index f97fe70..0000000 --- a/lib/bytes_per_element.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "float64": 8, - "float32": 4, - "int16": 2, - "int32": 4, - "int8": 1, - "uint16": 2, - "uint32": 4, - "uint8": 1, - "uint8c": 1, - "complex64": 8, - "complex128": 16 -} diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index a421711..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +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'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'highWaterMark': 9007199254740992 - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index ae28056..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,370 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var isComplex64Array = require( '@stdlib/assert-is-complex64array' ); -var isComplex128Array = require( '@stdlib/assert-is-complex128array' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var ctors = require( '@stdlib/array-typed-ctors' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var accessors = require( '@stdlib/array-base-accessors' ); -var adtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil = require( '@stdlib/math-base-special-ceil' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); -var log2 = require( '@stdlib/math-base-special-log2' ); -var min = require( '@stdlib/math-base-special-min' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var createPool = require( './pool.js' ); -var BYTES_PER_ELEMENT = require( './bytes_per_element.json' ); - - -// VARIABLES // - -var Complex64Array = ctors( 'complex64' ); -var Complex128Array = ctors( 'complex128' ); - - -// FUNCTIONS // - -/** -* Tests whether an array is a single-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a single-precision complex floating-point number array -*/ -function isCmplx64Array( arr ) { - return ( arr instanceof Complex64Array ); -} - -/** -* Tests whether an array is a double-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a double-precision complex floating-point number array -*/ -function isCmplx128Array( arr ) { - return ( arr instanceof Complex128Array ); -} - - -// MAIN // - -/** -* Creates a typed array pool. -* -* @param {Options} [options] - pool options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} allocator -* -* @example -* var typedarraypool = factory(); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -function factory( options ) { - var nbytes; - var pool; - var opts; - var err; - - opts = defaults(); - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - pool = createPool( ceil( log2( opts.highWaterMark ) ) ); - nbytes = 0; - - setReadOnly( malloc, 'malloc', malloc ); // circular reference - setReadOnly( malloc, 'calloc', calloc ); - setReadOnly( malloc, 'free', free ); - setReadOnly( malloc, 'clear', clear ); - setReadOnly( malloc, 'highWaterMark', opts.highWaterMark ); - setReadOnlyAccessor( malloc, 'nbytes', getBytes ); - - return malloc; - - /** - * Returns the number of allocated bytes. - * - * @private - * @returns {NonNegativeInteger} number of allocated bytes - */ - function getBytes() { - return nbytes; - } - - /** - * Returns an array buffer. - * - * @private - * @param {NonNegativeInteger} n - number of bytes - * @returns {(ArrayBuffer|null)} array buffer or null - */ - function arraybuffer( n ) { - var buf; - var i; - - // Convert the number of bytes to an index in our pool table: - i = log2( n ); - - // If we already have an available array buffer, use it... - if ( i < pool.length && pool[ i ].length ) { - return pool[ i ].pop(); - } - // Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate... - if ( nbytes+n > opts.highWaterMark ) { - return null; - } - buf = new ArrayBuffer( n ); - - // Update the running counter of allocated bytes: - nbytes += n; - - return buf; - } - - /** - * Returns a typed array. - * - * @private - * @param {Function} ctor - typed array constructor - * @param {NonNegativeInteger} len - view length - * @param {string} dtype - data type - * @returns {(TypedArray|null)} typed array or null - */ - function typedarray( ctor, len, dtype ) { - var buf; - if ( len === 0 ) { - return new ctor( 0 ); - } - buf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] ); - if ( buf === null ) { - return buf; - } - return new ctor( buf, 0, len ); - } - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length or an array-like object - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function malloc() { - var nargs; - var dtype; - var ctor; - var arr; - var out; - var set; - var get; - var len; - var i; - - nargs = arguments.length; - if ( nargs && isString( arguments[ nargs-1 ] ) ) { - nargs -= 1; - dtype = arguments[ nargs ]; - } else { - dtype = 'float64'; - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( '01H2Y,KZ', dtype ) ); - } - if ( nargs <= 0 ) { - return new ctor( 0 ); - } - // Check if provided a typed array length... - if ( isNonNegativeInteger( arguments[ 0 ] ) ) { - return typedarray( ctor, arguments[ 0 ], dtype ); - } - // Check if provided an array-like object containing data elements... - if ( isCollection( arguments[ 0 ] ) ) { - arr = arguments[ 0 ]; - len = arr.length; - if ( isComplex128Array( arr ) ) { - arr = reinterpret128( arr, 0 ); - } else if ( isComplex64Array( arr ) ) { - arr = reinterpret64( arr, 0 ); - } else if ( /^complex/.test( dtype ) ) { - // Assume we've been provided an array of interleaved real and imaginary components... - len /= 2; - } - out = typedarray( ctor, len, dtype ); - if ( out === null ) { - return out; - } - if ( isCmplx128Array( out ) || isCmplx64Array( out ) ) { - out.set( arr ); - return out; - } - // Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other "unsafe" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things... - get = accessors( adtype( arr ) ).accessors[ 0 ]; - set = accessors( dtype ).accessors[ 1 ]; - for ( i = 0; i < len; i++ ) { - set( out, i, get( arr, i ) ); - } - return out; - } - throw new TypeError( format( '01H2r,N0', arguments[ 0 ] ) ); - } - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {NonNegativeInteger} [len=0] - array length - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function calloc() { - var nargs; - var out; - var tmp; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - out = malloc(); - } else if ( nargs === 1 ) { - out = malloc( arguments[ 0 ] ); - } else { - out = malloc( arguments[ 0 ], arguments[ 1 ] ); - } - if ( out !== null ) { - // Initialize the memory... - if ( isCmplx128Array( out ) ) { - tmp = reinterpret128( out, 0 ); - } else if ( isCmplx64Array( out ) ) { - tmp = reinterpret64( out, 0 ); - } else { - tmp = out; - } - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = 0.0; - } - } - return out; - } - - /** - * Frees a typed array or typed array buffer. - * - * ## Notes - * - * - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., "freeing" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool. - * - * @private - * @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free - * @throws {TypeError} must provide a typed array or typed array buffer - * @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed - */ - function free( buf ) { - var n; - var p; - var i; - if ( isTypedArrayLike( buf ) && buf.buffer ) { - buf = buf.buffer; - } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( '01H2s,N1', buf ) ); - } - if ( buf.byteLength > 0 ) { - n = floor( log2( buf.byteLength ) ); - - // Prohibit "freeing" array buffers which would potentially allow users to circumvent high water mark limits: - n = min( pool.length-1, n ); - - // Ensure that we do not attempt to free the same buffer more than once... - p = pool[ n ]; - for ( i = 0; i < p.length; i++ ) { - if ( p[ i ] === buf ) { - return false; - } - } - // Add the buffer to our pool of free buffers: - p.push( buf ); - } - return true; - } - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @private - */ - function clear() { - var i; - for ( i = 0; i < pool.length; i++ ) { - pool[ i ].length = 0; - } - nbytes = 0; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6c12a4e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Typed array pool. -* -* @module @stdlib/array-pool -* -* @example -* var typedarraypool = require( '@stdlib/array-pool' ); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8f69ee3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,63 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @name typedarraypool -* @type {Function} -* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a valid array length or an array-like object -* @throws {TypeError} must provide a recognized data type -* @returns {(TypedArray|null)} typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -var typedarraypool = factory(); - - -// EXPORTS // - -module.exports = typedarraypool; diff --git a/lib/pool.js b/lib/pool.js deleted file mode 100644 index 5abd287..0000000 --- a/lib/pool.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Initializes a cache for pooled typed array buffers. -* -* @private -* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size -* @returns {ArrayArray} initialized cache -*/ -function pool( n ) { - var out; - var i; - - out = []; - for ( i = 0; i < n+1; i++ ) { - out.push( [] ); - } - return out; -} - - -// EXPORTS // - -module.exports = pool; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 95667c7..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'highWaterMark': 1024 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '01H2V,FD', options ) ); - } - if ( hasOwnProp( options, 'highWaterMark' ) ) { - opts.highWaterMark = options.highWaterMark; - if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( '01H2t,G9', 'highWaterMark', opts.highWaterMark ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 7d353bb..0399bd9 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Typed array pool.", "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,76 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessors": "^0.0.2", - "@stdlib/array-buffer": "^0.0.6", - "@stdlib/array-dtype": "^0.0.6", - "@stdlib/array-typed-ctors": "^0.0.6", - "@stdlib/assert-has-own-property": "^0.0.7", - "@stdlib/assert-is-arraybuffer": "^0.0.8", - "@stdlib/assert-is-collection": "^0.0.8", - "@stdlib/assert-is-complex128array": "^0.0.7", - "@stdlib/assert-is-complex64array": "^0.0.7", - "@stdlib/assert-is-nonnegative-integer": "^0.0.7", - "@stdlib/assert-is-plain-object": "^0.0.7", - "@stdlib/assert-is-string": "^0.0.8", - "@stdlib/assert-is-typed-array-like": "^0.0.8", - "@stdlib/math-base-special-ceil": "^0.0.8", - "@stdlib/math-base-special-ceil2": "^0.0.6", - "@stdlib/math-base-special-floor": "^0.0.8", - "@stdlib/math-base-special-log2": "^0.0.7", - "@stdlib/math-base-special-min": "^0.0.7", - "@stdlib/strided-base-reinterpret-complex128": "^0.0.2", - "@stdlib/strided-base-reinterpret-complex64": "^0.0.2", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.0.7", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.7" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.0.6", - "@stdlib/array-complex64": "^0.0.6", - "@stdlib/array-float32": "^0.0.6", - "@stdlib/array-float64": "^0.0.6", - "@stdlib/array-int16": "^0.0.6", - "@stdlib/array-int32": "^0.0.6", - "@stdlib/array-int8": "^0.0.6", - "@stdlib/array-uint16": "^0.0.6", - "@stdlib/array-uint32": "^0.0.6", - "@stdlib/array-uint8": "^0.0.7", - "@stdlib/array-uint8c": "^0.0.8", - "@stdlib/assert-instance-of": "^0.0.8", - "@stdlib/assert-is-complex-typed-array": "^0.0.6", - "@stdlib/assert-is-function": "^0.0.8", - "@stdlib/assert-is-typed-array": "^0.0.6", - "@stdlib/bench": "^0.0.12", - "@stdlib/complex-float32": "^0.0.7", - "@stdlib/complex-float64": "^0.0.8", - "@stdlib/complex-imag": "^0.0.7", - "@stdlib/complex-imagf": "^0.0.1", - "@stdlib/complex-real": "^0.0.7", - "@stdlib/complex-realf": "^0.0.1", - "@stdlib/math-base-special-pow": "^0.0.7", - "@stdlib/random-base-randu": "^0.0.8", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a07c9e6 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 396aee2..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,2240 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function (no options)', function test( t ) { - t.strictEqual( typeof factory(), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - t.strictEqual( typeof factory( {} ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided a `highWaterMark` option which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (length)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a function which returns a typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, length)', function test( t ) { - var typedarraypool = factory(); - var arr; - - arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a `malloc` method which is a circular reference', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - var buf; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the returned function is a property which returns the pool\'s high water mark', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function supports specifying a high water mark which limits the total amount of memory a pool can allocate', function test( t ) { - var typedarraypool; - var arr1; - var arr2; - - typedarraypool = factory({ - 'highWaterMark': 64 // bytes - }); - - typedarraypool.clear(); - - arr1 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr1.length, 8, 'returns expected value' ); - t.strictEqual( arr1.byteLength, 64, 'returns expected value' ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - typedarraypool.free( arr1 ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Create an array which is less than or equal to the high water mark: - arr2 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr2.length, 8, 'returns expected value' ); - t.strictEqual( arr2.byteLength, 64, 'returns expected value' ); - - typedarraypool.free( arr2 ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a property which returns the total number of accumulated bytes', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var typedarraypool; - var arrs; - var i; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 54aa5ee..0000000 --- a/test/test.js +++ /dev/null @@ -1,1797 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var typedarraypool = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -}); From b7542db284e96a031a902dccc4fc2dfa54a7c2a0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 17:35:41 +0000 Subject: [PATCH 035/103] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index edfecbe..ae28056 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -34,7 +34,7 @@ var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); var accessors = require( '@stdlib/array-base-accessors' ); var adtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ArrayBuffer = require( '@stdlib/array-buffer' ); var ceil = require( '@stdlib/math-base-special-ceil' ); var floor = require( '@stdlib/math-base-special-floor' ); @@ -226,7 +226,7 @@ function factory( options ) { } ctor = ctors( dtype ); if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '01H2Y,KZ', dtype ) ); } if ( nargs <= 0 ) { return new ctor( 0 ); @@ -263,7 +263,7 @@ function factory( options ) { } return out; } - throw new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) ); + throw new TypeError( format( '01H2r,N0', arguments[ 0 ] ) ); } /** @@ -329,7 +329,7 @@ function factory( options ) { if ( isTypedArrayLike( buf ) && buf.buffer ) { buf = buf.buffer; } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) ); + throw new TypeError( format( '01H2s,N1', buf ) ); } if ( buf.byteLength > 0 ) { n = floor( log2( buf.byteLength ) ); diff --git a/lib/validate.js b/lib/validate.js index ce54890..95667c7 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '01H2V,FD', options ) ); } if ( hasOwnProp( options, 'highWaterMark' ) ) { opts.highWaterMark = options.highWaterMark; if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) ); + return new TypeError( format( '01H2t,G9', 'highWaterMark', opts.highWaterMark ) ); } } return null; diff --git a/package.json b/package.json index 79df9ec..f2284d8 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "@stdlib/math-base-special-min": "^0.1.0", "@stdlib/strided-base-reinterpret-complex128": "^0.1.0", "@stdlib/strided-base-reinterpret-complex64": "^0.1.0", - "@stdlib/string-format": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0", "@stdlib/types": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.0" From 2972dabd1baa39e148c3e8a91d8175378af07dd3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 17:59:16 +0000 Subject: [PATCH 036/103] Remove files --- index.d.ts | 359 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6541 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 c6a3785..0000000 --- a/index.d.ts +++ /dev/null @@ -1,359 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; -import ArrayBuffer = require( '@stdlib/array-buffer' ); - -/** -* Typed array or null. -*/ -type TypedArrayOrNull = RealOrComplexTypedArray | null; - -/** -* Interface defining pool options. -*/ -interface Options { - /** - * Maximum total memory which can be allocated. - */ - highWaterMark?: number; -} - -/** -* Pool interface. -*/ -interface Pool { - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr = typedarraypool(); - * // returns [] - * - * @example - * var arr = typedarraypool( 'float32' ); - * // returns [] - */ - ( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * // Allocate an array of doubles: - * var arr = typedarraypool( 5, 'float64' ); - * // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * typedarraypool.free( arr ); - * - * @example - * var arr1 = typedarraypool( [ 0.5, 0.5, 0.5 ] ); - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * @example - * var arr1 = [ 0.5, 0.5, 0.5 ]; - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - */ - ( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc(); - * // returns [] - * - * var arr2 = typedarraypool.calloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param length - typed array length - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc( 5 ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * var arr2 = typedarraypool.calloc( 5, 'uint8' ); - * // returns [ 0, 0, 0, 0, 0 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( length: number, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc(); - * // returns [] - * - * var arr2 = typedarraypool.malloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc( 5 ); - * // returns - * - * var arr2 = typedarraypool.malloc( 5, 'uint8' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 5.0, -3.0, 2.0 ] ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr2 = typedarraypool.malloc( arr1 ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr3 = typedarraypool.malloc( arr1, 'int32' ); - * // returns [ 5, -3, 2 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * typedarraypool.free( arr3 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ] ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * var arr2 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ], 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Frees a typed array or typed array buffer for use in a future allocation. - * - * @param buf - typed array or typed array buffer to free - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array for use in a future allocation: - * typedarraypool.free( arr ); - * - * // Create another typed array: - * arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array buffer for use in a future allocation: - * typedarraypool.free( arr.buffer ); - */ - free( buf: RealOrComplexTypedArray | ArrayBuffer ): void; - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr ); - * - * // ... - * - * // Clear all freed buffers: - * typedarraypool.clear(); - */ - clear(): void; - - /** - * Read-only property returning the pool's high water mark. - * - * ## Notes - * - * - Once a high water mark is reached, typed array allocation fails. - * - * @example - * var limit = typedarraypool.highWaterMark; - * // returns - */ - readonly highWaterMark: number; - - /** - * Read-only property returning the total number of allocated bytes. - * - * @example - * var arr = typedarraypool( 5, 'float64' ); - * - * var nbytes = typedarraypool.nbytes; - * // returns - */ - readonly nbytes: number; - - /** - * Creates a typed array pool. - * - * @param options - pool options - * @param options.highWaterMark - maximum total memory which can be allocated - * @throws must provide valid options - * @returns allocator - * - * @example - * var allocator = typedarraypool.factory(); - * - * // Allocate an array of doubles: - * var arr = allocator( 5, 'float64' ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * allocator.free( arr ); - */ - factory( options?: Options ): Pool; -} - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @param arg - an array length or an array-like object -* @param dtype - data type (default: 'float64') -* @returns typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -declare var typedarraypool: Pool; - - -// EXPORTS // - -export = typedarraypool; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 284e557..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessors@v0.0.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.0.7-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";function k(e,t){return y(t)?w(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(c("01H2t,G9","highWaterMark",e.highWaterMark)):null:new TypeError(c("01H2V,FD",t))}function M(e){var t,r;for(t=[],r=0;rH.highWaterMark?null:(t=new j(e),w+=e,t)}function G(e,t,r){var s;return 0===t?new e(0):null===(s=F(b(t)*W[r]))?s:new e(s,0,t)}function K(){var e,i,n,l,j,g,u,b,v;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(n=d(i)))throw new TypeError(c("01H2Y,KZ",i));if(e<=0)return new n(0);if(r(arguments[0]))return G(n,arguments[0],i);if(s(arguments[0])){if(b=(l=arguments[0]).length,m(l)?l=h(l,0):o(l)?l=a(l,0):/^complex/.test(i)&&(b/=2),null===(j=G(n,b,i)))return j;if(L(j)||T(j))return j.set(l),j;for(u=p(f(l)).accessors[0],g=p(i).accessors[1],v=0;v0){for(t=u(v(e.byteLength)),t=x(E.length-1,t),r=E[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '01H2Y,KZ', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = accessors( adtype( arr ) ).accessors[ 0 ];\n\t\t\tset = accessors( dtype ).accessors[ 1 ];\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '01H2r,N0', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( '01H2s,N1', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","accessors","adtype","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;6nEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,WAAY,gBAAiBP,EAAKI,gBAG3D,KARC,IAAIE,UAAWC,EAAQ,WAAYN,GAS5C,CC/BA,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,iHCaIG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EC/EO,CACNI,cAAiB,kBD+EbkB,UAAUC,SACdF,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOgB,EAAYC,EAAMC,EAAM1B,EAAKI,iBACpCgB,EAAS,EAETO,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB5B,EAAKI,eAC3C4B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOb,CACP,CASD,SAASc,EAAazB,GACrB,IAAI0B,EACAxB,EAMJ,OAHAA,EAAIe,EAAMjB,IAGDD,EAAKe,QAAUf,EAAMG,GAAIY,OAC1Bf,EAAMG,GAAIyB,MAGbhB,EAAOX,EAAIT,EAAKI,cACb,MAER+B,EAAM,IAAIE,EAAa5B,GAGvBW,GAAUX,EAEH0B,EACP,CAWD,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,EACzB,CAkBD,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAtB,EACAP,EACAmC,EACAC,EACAN,EACA7B,EAUJ,GALC8B,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAOzB,EAAO2B,IAEb,MAAM,IAAInC,UAAWC,EAAQ,WAAYkC,IAE1C,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKlC,EAAsBiB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAvB,EAAMK,UAAW,IACPC,OACL0B,EAAmBhC,GACvBA,EAAMiC,EAAgBjC,EAAK,GAChBkC,EAAkBlC,GAC7BA,EAAMmC,EAAenC,EAAK,GACf,WAAWoC,KAAMZ,KAE5BD,GAAO,GAGK,QADb9B,EAAM4B,EAAYC,EAAMC,EAAKC,IAE5B,OAAO/B,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAImC,IAAK5B,GACFP,EAKR,IAFAoC,EAAMQ,EAAWC,EAAQtC,IAAQqC,UAAW,GAC5CT,EAAMS,EAAWb,GAAQa,UAAW,GAC9B3C,EAAI,EAAGA,EAAI6B,EAAK7B,IACrBkC,EAAKnC,EAAKC,EAAGmC,EAAK7B,EAAKN,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,WAAYe,UAAW,IACpD,CAgBD,SAASO,IACR,IAAIe,EACAlC,EACA8C,EACA7C,EAUJ,GAAa,QANZD,EADc,KADfkC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCkC,EADItC,EAAiBR,GACfwC,EAAgBxC,EAAK,GAChBM,EAAgBN,GACrB0C,EAAe1C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAI6C,EAAIjC,OAAQZ,IAC5B6C,EAAK7C,GAAM,EAGb,OAAOD,CACP,CAcD,SAASoB,EAAMK,GACd,IAAI1B,EACAgD,EACA9C,EACJ,GAAK+C,EAAkBvB,IAASA,EAAIwB,OACnCxB,EAAMA,EAAIwB,YACJ,IAAMC,EAAezB,GAC3B,MAAM,IAAI7B,UAAWC,EAAQ,WAAY4B,IAE1C,GAAKA,EAAI0B,WAAa,EAAI,CAQzB,IAPApD,EAAIqD,EAAOpC,EAAMS,EAAI0B,aAGrBpD,EAAIsD,EAAKvD,EAAKe,OAAO,EAAGd,GAGxBgD,EAAIjD,EAAMC,GACJE,EAAI,EAAGA,EAAI8C,EAAElC,OAAQZ,IAC1B,GAAK8C,EAAG9C,KAAQwB,EACf,OAAO,EAITsB,EAAE7C,KAAMuB,EACR,CACD,OAAO,CACP,CAOD,SAASJ,IACR,IAAIpB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKe,OAAQZ,IAC7BH,EAAMG,GAAIY,OAAS,EAEpBH,EAAS,CACT,CACF,CEnTG,IAAC4C,EAAiB7C,ICPrBQ,EAAAsC,EAAA,UAAA9C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a07c9e6..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5bb2d77adde80e291a7c70cf51026b4a99dab23c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 18:01:35 +0000 Subject: [PATCH 037/103] 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 | 43 +- benchmark/benchmark.calloc.js | 246 - benchmark/benchmark.factory.js | 71 - benchmark/benchmark.js | 246 - benchmark/benchmark.length.complex128.js | 102 - benchmark/benchmark.length.complex64.js | 102 - benchmark/benchmark.length.float32.js | 102 - benchmark/benchmark.length.float64.js | 102 - benchmark/benchmark.length.int16.js | 102 - benchmark/benchmark.length.int32.js | 102 - benchmark/benchmark.length.int8.js | 102 - benchmark/benchmark.length.uint16.js | 102 - benchmark/benchmark.length.uint32.js | 102 - benchmark/benchmark.length.uint8.js | 102 - benchmark/benchmark.length.uint8c.js | 102 - benchmark/benchmark.malloc.js | 246 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 347 -- docs/types/test.ts | 193 - examples/index.js | 80 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/bytes_per_element.json | 13 - lib/defaults.js | 42 - lib/factory.js | 370 -- lib/index.js | 56 - lib/main.js | 63 - lib/pool.js | 44 - lib/validate.js | 66 - package.json | 97 +- stats.html | 6177 +++++++++++++++++++++ test/test.factory.js | 2240 -------- test/test.js | 1797 ------ 60 files changed, 6206 insertions(+), 10538 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.calloc.js delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.complex128.js delete mode 100644 benchmark/benchmark.length.complex64.js delete mode 100644 benchmark/benchmark.length.float32.js delete mode 100644 benchmark/benchmark.length.float64.js delete mode 100644 benchmark/benchmark.length.int16.js delete mode 100644 benchmark/benchmark.length.int32.js delete mode 100644 benchmark/benchmark.length.int8.js delete mode 100644 benchmark/benchmark.length.uint16.js delete mode 100644 benchmark/benchmark.length.uint32.js delete mode 100644 benchmark/benchmark.length.uint8.js delete mode 100644 benchmark/benchmark.length.uint8c.js delete mode 100644 benchmark/benchmark.malloc.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/bytes_per_element.json delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/pool.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ea35f20..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/array/pool) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 fc6d38a..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/array/pool) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 9ef1395..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 91f2b93..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,783 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -493,7 +492,7 @@ console.log( 'nbytes: %d', typedarray.nbytes ); ## 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]. @@ -559,7 +558,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm diff --git a/benchmark/benchmark.calloc.js b/benchmark/benchmark.calloc.js deleted file mode 100644 index e5a1c77..0000000 --- a/benchmark/benchmark.calloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':calloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index f7cd676..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = typedarray.factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:highWaterMark', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'highWaterMark': 0 - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.highWaterMark = i; - f = typedarray.factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a023d2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.complex128.js b/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 47b623b..0000000 --- a/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex64.js b/benchmark/benchmark.length.complex64.js deleted file mode 100644 index 40a412b..0000000 --- a/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float32.js b/benchmark/benchmark.length.float32.js deleted file mode 100644 index 0227ed7..0000000 --- a/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float64.js b/benchmark/benchmark.length.float64.js deleted file mode 100644 index 2dbac1c..0000000 --- a/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int16.js b/benchmark/benchmark.length.int16.js deleted file mode 100644 index e2a8adc..0000000 --- a/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int32.js b/benchmark/benchmark.length.int32.js deleted file mode 100644 index e4df0aa..0000000 --- a/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int8.js b/benchmark/benchmark.length.int8.js deleted file mode 100644 index 7ceac11..0000000 --- a/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint16.js b/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 9a532b6..0000000 --- a/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint32.js b/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 98f2d7f..0000000 --- a/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8.js b/benchmark/benchmark.length.uint8.js deleted file mode 100644 index 8359249..0000000 --- a/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8c.js b/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index d47d023..0000000 --- a/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.malloc.js b/benchmark/benchmark.malloc.js deleted file mode 100644 index d4eea72..0000000 --- a/benchmark/benchmark.malloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':malloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 9689761..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/array/pool" -%% click B href "https://github.com/stdlib-js/array-pool/tree/main" -%% click C href "https://github.com/stdlib-js/array-pool/tree/production" -%% click D href "https://github.com/stdlib-js/array-pool/tree/esm" -%% click E href "https://github.com/stdlib-js/array-pool/tree/deno" -%% click F href "https://github.com/stdlib-js/array-pool/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/pool -[production-url]: https://github.com/stdlib-js/array-pool/tree/production -[deno-url]: https://github.com/stdlib-js/array-pool/tree/deno -[umd-url]: https://github.com/stdlib-js/array-pool/tree/umd -[esm-url]: https://github.com/stdlib-js/array-pool/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 5160b6f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import typedarraypool from '../docs/types/index'; -export = typedarraypool; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 9d31d69..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var l=function(n,i){return function(){return i||n((i={exports:{}}).exports,i),i.exports}};var k=l(function(kr,M){ -function D(){return{highWaterMark:9007199254740992}}M.exports=D -});var E=l(function(Ar,W){ -var G=require('@stdlib/assert-is-plain-object/dist'),H=require('@stdlib/assert-has-own-property/dist'),J=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,A=require('@stdlib/error-tools-fmtprodmsg/dist');function K(n,i){return G(i)?H(i,"highWaterMark")&&(n.highWaterMark=i.highWaterMark,!J(n.highWaterMark))?new TypeError(A('01H2t',"highWaterMark",n.highWaterMark)):null:new TypeError(A('01H2V',i));}W.exports=K -});var C=l(function(Wr,T){ -function Q(n){var i,u;for(i=[],u=0;uv.highWaterMark?null:(e=new ur(r),i+=r,e)}function d(r,e,t){var a;return e===0?new r(0):(a=_(lr(e)*hr[t]),a===null?a:new r(a,0,e))}function s(){var r,e,t,a,o,x,w,c,f;if(r=arguments.length,r&&X(arguments[r-1])?(r-=1,e=arguments[r]):e="float64",t=y(e),t===null)throw new TypeError(m('01H2Y',e));if(r<=0)return new t(0);if(Z(arguments[0]))return d(t,arguments[0],e);if($(arguments[0])){if(a=arguments[0],c=a.length,tr(a)?a=P(a,0):ar(a)?a=b(a,0):/^complex/.test(e)&&(c/=2),o=d(t,c,e),o===null)return o;if(L(o)||N(o))return o.set(a),o;for(w=B(nr(a)).accessors[0],x=B(e).accessors[1],f=0;f0){for(e=or(p(r.byteLength)),e=vr(u.length-1,e),t=u[e],a=0;a[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = accessors( adtype( arr ) ).accessors[ 0 ];\n\t\t\tset = accessors( dtype ).accessors[ 1 ];\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nmodule.exports = typedarraypool;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* var typedarraypool = require( '@stdlib/array-pool' );\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,cAAiB,gBAClB,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,eAAgB,IACzCD,EAAK,cAAgBC,EAAQ,cACxB,CAACJ,EAAsBG,EAAK,aAAc,GACvC,IAAI,UAAWF,EAAQ,2EAA4E,gBAAiBE,EAAK,aAAc,CAAE,EAG3I,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cA6BA,SAASC,EAAM,EAAI,CAClB,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAI,EAAE,EAAGA,IACrBD,EAAI,KAAM,CAAC,CAAE,EAEd,OAAOA,CACR,CAKAF,EAAO,QAAUC,IC3CjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,QAAW,EACX,QAAW,EACX,MAAS,EACT,MAAS,EACT,KAAQ,EACR,OAAU,EACV,OAAU,EACV,MAAS,EACT,OAAU,EACT,UAAa,EACb,WAAc,EAChB,ICZA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAe,QAAS,8BAA+B,EACvDC,GAAmB,QAAS,oCAAqC,EACjEC,GAAgB,QAAS,+BAAgC,EACzDC,GAAmB,QAAS,kCAAmC,EAC/DC,GAAoB,QAAS,mCAAoC,EACjEC,EAAc,QAAS,uDAAwD,EAC/EC,GAAsB,QAAS,uDAAwD,EACvFC,EAAQ,QAAS,2BAA4B,EAC7CC,EAAgB,QAAS,4CAA6C,EACtEC,EAAiB,QAAS,6CAA8C,EACxEC,EAAY,QAAS,8BAA+B,EACpDC,GAAS,QAAS,qBAAsB,EACxCC,EAAS,QAAS,uBAAwB,EAC1CC,GAAc,QAAS,sBAAuB,EAC9CC,GAAO,QAAS,gCAAiC,EACjDC,GAAQ,QAAS,iCAAkC,EACnDC,GAAQ,QAAS,iCAAkC,EACnDC,EAAO,QAAS,gCAAiC,EACjDC,GAAM,QAAS,+BAAgC,EAC/CC,GAAW,IACXC,GAAW,IACXC,GAAa,IACbC,GAAoB,IAKpBC,GAAiBhB,EAAO,WAAY,EACpCiB,GAAkBjB,EAAO,YAAa,EAY1C,SAASkB,EAAgBC,EAAM,CAC9B,OAASA,aAAeH,EACzB,CASA,SAASI,EAAiBD,EAAM,CAC/B,OAASA,aAAeF,EACzB,CA6BA,SAASI,GAASC,EAAU,CAC3B,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,EAAOb,GAAS,EACX,UAAU,SACdc,EAAMb,GAAUY,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAAF,EAAOV,GAAYP,GAAMG,EAAMe,EAAK,aAAc,CAAE,CAAE,EACtDF,EAAS,EAETzB,EAAa6B,EAAQ,SAAUA,CAAO,EACtC7B,EAAa6B,EAAQ,SAAUC,CAAO,EACtC9B,EAAa6B,EAAQ,OAAQE,CAAK,EAClC/B,EAAa6B,EAAQ,QAASG,CAAM,EACpChC,EAAa6B,EAAQ,gBAAiBF,EAAK,aAAc,EACzD1B,GAAqB4B,EAAQ,SAAUI,CAAS,EAEzCJ,EAQP,SAASI,GAAW,CACnB,OAAOR,CACR,CASA,SAASS,EAAaC,EAAI,CACzB,IAAIC,EACAC,EAMJ,OAHAA,EAAIzB,EAAMuB,CAAE,EAGPE,EAAIX,EAAK,QAAUA,EAAMW,CAAE,EAAE,OAC1BX,EAAMW,CAAE,EAAE,IAAI,EAGjBZ,EAAOU,EAAIR,EAAK,cACb,MAERS,EAAM,IAAI5B,GAAa2B,CAAE,EAGzBV,GAAUU,EAEHC,EACR,CAWA,SAASE,EAAYC,EAAMC,EAAKC,EAAQ,CACvC,IAAIL,EACJ,OAAKI,IAAQ,EACL,IAAID,EAAM,CAAE,GAEpBH,EAAMF,EAAavB,GAAO6B,CAAI,EAAEvB,GAAmBwB,CAAM,CAAE,EACtDL,IAAQ,KACLA,EAED,IAAIG,EAAMH,EAAK,EAAGI,CAAI,EAC9B,CAkBA,SAASX,GAAS,CACjB,IAAIa,EACAD,EACAF,EACAlB,EACAsB,EACAC,EACAC,EACAL,EACAH,EAUJ,GARAK,EAAQ,UAAU,OACbA,GAASjD,EAAU,UAAWiD,EAAM,CAAE,CAAE,GAC5CA,GAAS,EACTD,EAAQ,UAAWC,CAAM,GAEzBD,EAAQ,UAETF,EAAOrC,EAAOuC,CAAM,EACfF,IAAS,KACb,MAAM,IAAI,UAAWhC,EAAQ,sEAAuEkC,CAAM,CAAE,EAE7G,GAAKC,GAAS,EACb,OAAO,IAAIH,EAAM,CAAE,EAGpB,GAAK7C,EAAsB,UAAW,CAAE,CAAE,EACzC,OAAO4C,EAAYC,EAAM,UAAW,CAAE,EAAGE,CAAM,EAGhD,GAAK9C,EAAc,UAAW,CAAE,CAAE,EAAI,CAYrC,GAXA0B,EAAM,UAAW,CAAE,EACnBmB,EAAMnB,EAAI,OACLtB,GAAmBsB,CAAI,EAC3BA,EAAMjB,EAAgBiB,EAAK,CAAE,EAClBvB,GAAkBuB,CAAI,EACjCA,EAAMlB,EAAekB,EAAK,CAAE,EACjB,WAAW,KAAMoB,CAAM,IAElCD,GAAO,GAERG,EAAML,EAAYC,EAAMC,EAAKC,CAAM,EAC9BE,IAAQ,KACZ,OAAOA,EAER,GAAKrB,EAAiBqB,CAAI,GAAKvB,EAAgBuB,CAAI,EAClD,OAAAA,EAAI,IAAKtB,CAAI,EACNsB,EAKR,IAFAE,EAAMxC,EAAWC,GAAQe,CAAI,CAAE,EAAE,UAAW,CAAE,EAC9CuB,EAAMvC,EAAWoC,CAAM,EAAE,UAAW,CAAE,EAChCJ,EAAI,EAAGA,EAAIG,EAAKH,IACrBO,EAAKD,EAAKN,EAAGQ,EAAKxB,EAAKgB,CAAE,CAAE,EAE5B,OAAOM,CACR,CACA,MAAM,IAAI,UAAWpC,EAAQ,wGAAyG,UAAW,CAAE,CAAE,CAAE,CACxJ,CAgBA,SAASuB,GAAS,CACjB,IAAIY,EACAC,EACAG,EACAT,EAUJ,GARAK,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAMd,EAAO,EACFa,IAAU,EACrBC,EAAMd,EAAQ,UAAW,CAAE,CAAE,EAE7Bc,EAAMd,EAAQ,UAAW,CAAE,EAAG,UAAW,CAAE,CAAE,EAEzCc,IAAQ,KASZ,IAPKrB,EAAiBqB,CAAI,EACzBG,EAAM1C,EAAgBuC,EAAK,CAAE,EAClBvB,EAAgBuB,CAAI,EAC/BG,EAAM3C,EAAewC,EAAK,CAAE,EAE5BG,EAAMH,EAEDN,EAAI,EAAGA,EAAIS,EAAI,OAAQT,IAC5BS,EAAKT,CAAE,EAAI,EAGb,OAAOM,CACR,CAcA,SAASZ,EAAMK,EAAM,CACpB,IAAID,EACAY,EACAV,EACJ,GAAKzC,GAAkBwC,CAAI,GAAKA,EAAI,OACnCA,EAAMA,EAAI,eACC,CAACvC,GAAeuC,CAAI,EAC/B,MAAM,IAAI,UAAW7B,EAAQ,4EAA6E6B,CAAI,CAAE,EAEjH,GAAKA,EAAI,WAAa,EAAI,CAQzB,IAPAD,EAAIzB,GAAOE,EAAMwB,EAAI,UAAW,CAAE,EAGlCD,EAAItB,GAAKa,EAAK,OAAO,EAAGS,CAAE,EAG1BY,EAAIrB,EAAMS,CAAE,EACNE,EAAI,EAAGA,EAAIU,EAAE,OAAQV,IAC1B,GAAKU,EAAGV,CAAE,IAAMD,EACf,MAAO,GAITW,EAAE,KAAMX,CAAI,CACb,CACA,MAAO,EACR,CAOA,SAASJ,GAAQ,CAChB,IAAIK,EACJ,IAAMA,EAAI,EAAGA,EAAIX,EAAK,OAAQW,IAC7BX,EAAMW,CAAE,EAAE,OAAS,EAEpBZ,EAAS,CACV,CACD,CAKAjC,EAAO,QAAU+B,KCjXjB,IAAAyB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAU,IAmCVC,GAAiBD,GAAQ,EAK7BD,EAAO,QAAUE,KCnBjB,IAAIC,GAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,GAAU,IAKdF,GAAaC,EAAM,UAAWC,EAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isNonNegativeInteger", "format", "validate", "opts", "options", "require_pool", "__commonJSMin", "exports", "module", "pool", "out", "i", "require_bytes_per_element", "__commonJSMin", "exports", "module", "require_factory", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isCollection", "isTypedArrayLike", "isArrayBuffer", "isComplex64Array", "isComplex128Array", "setReadOnly", "setReadOnlyAccessor", "ctors", "reinterpret64", "reinterpret128", "accessors", "adtype", "format", "ArrayBuffer", "ceil", "floor", "ceil2", "log2", "min", "defaults", "validate", "createPool", "BYTES_PER_ELEMENT", "Complex64Array", "Complex128Array", "isCmplx64Array", "arr", "isCmplx128Array", "factory", "options", "nbytes", "pool", "opts", "err", "malloc", "calloc", "free", "clear", "getBytes", "arraybuffer", "n", "buf", "i", "typedarray", "ctor", "len", "dtype", "nargs", "out", "set", "get", "tmp", "p", "require_main", "__commonJSMin", "exports", "module", "factory", "typedarraypool", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5244595..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,347 +0,0 @@ - -{{alias}}( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - Memory is **uninitialized**, which means that the contents of a returned - typed array may contain sensitive contents. - - The function supports the following data types: - - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - The default typed array data type is `float64`. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}() - [] - > arr = {{alias}}( 'float32' ) - [] - - -{{alias}}( length[, dtype] ) - Returns an uninitialized typed array having a specified length from a typed - array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > arr = {{alias}}( 5, 'int32' ) - - - -{{alias}}( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - This method shares the same security vulnerabilities mentioned above. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc() - - > arr = {{alias}}.malloc( 'float32' ) - - - -{{alias}}.malloc( length[, dtype] ) - Returns a typed array having a specified length from a typed array memory - pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc( 5 ) - - > arr = {{alias}}.malloc( 5, 'int32' ) - - - -{{alias}}.malloc( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}.malloc( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.calloc( [dtype] ) - Returns a zero-initialized typed array from a typed array memory pool. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc() - [] - > arr = {{alias}}.calloc( 'float32' ) - [] - - -{{alias}}.calloc( length[, dtype] ) - Returns a zero-initialized typed array having a specified length from a - typed array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}.calloc( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}.free( buf ) - Frees a typed array or typed array buffer for use in a future allocation. - - Parameters - ---------- - buf: TypedArray|ArrayBuffer - Typed array or typed array buffer to free. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ) - - -{{alias}}.clear() - Clears the typed array pool allowing garbage collection of previously - allocated (and currently free) array buffers. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - > {{alias}}.clear() - - -{{alias}}.highWaterMark - Read-only property returning the pool's high water mark. - - Once a high water mark is reached, typed array allocation fails. - - Examples - -------- - > {{alias}}.highWaterMark - - -{{alias}}.nbytes - Read-only property returning the total number of allocated bytes. - - The returned value is the total accumulated value. Hence, anytime a pool - must allocate a new array buffer (i.e., more memory), the pool increments - this value. - - The only time this value is decremented is when a pool is cleared. - - This behavior means that, while allocated buffers which are never freed may, - in fact, be garbage collected, they continue to count against the high water - mark limit. - - Accordingly, you should *always* free allocated buffers in order to prevent - the pool from believing that non-freed buffers are continually in use. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.nbytes - - -{{alias}}.factory( [options] ) - Creates a typed array pool. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.highWaterMark: integer (optional) - Maximum total memory (in bytes) which can be allocated. - - Returns - ------- - fcn: Function - Function for creating typed arrays from a typed array memory pool. - - Examples - -------- - > var pool = {{alias}}.factory(); - > var arr1 = pool( 3, 'float64' ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1014bba..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,193 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-empty */ -/* tslint:disable:no-unused-expression */ - -import typedarraypool = require( './index' ); - - -// TESTS // - -// The function returns a typed array or null... -{ - typedarraypool(); // $ExpectType TypedArrayOrNull - typedarraypool( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the function is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool( true ); // $ExpectError - typedarraypool( false ); // $ExpectError - typedarraypool( null ); // $ExpectError - typedarraypool( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized data type... -{ - typedarraypool( 4, true ); // $ExpectError - typedarraypool( 4, false ); // $ExpectError - typedarraypool( 4, null ); // $ExpectError - typedarraypool( 4, 'abc' ); // $ExpectError - typedarraypool( 4, 123 ); // $ExpectError - typedarraypool( 4, [] ); // $ExpectError - typedarraypool( 4, {} ); // $ExpectError - typedarraypool( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an incorrect number of arguments... -{ - typedarraypool( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `malloc` method which returns a typed array or null... -{ - typedarraypool.malloc(); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.malloc( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `malloc` method is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool.malloc( true ); // $ExpectError - typedarraypool.malloc( false ); // $ExpectError - typedarraypool.malloc( null ); // $ExpectError - typedarraypool.malloc( {} ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.malloc( 4, true ); // $ExpectError - typedarraypool.malloc( 4, false ); // $ExpectError - typedarraypool.malloc( 4, null ); // $ExpectError - typedarraypool.malloc( 4, 'abc' ); // $ExpectError - typedarraypool.malloc( 4, 123 ); // $ExpectError - typedarraypool.malloc( 4, [] ); // $ExpectError - typedarraypool.malloc( 4, {} ); // $ExpectError - typedarraypool.malloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided an incorrect number of arguments... -{ - typedarraypool.malloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `calloc` method which returns a typed array or null... -{ - typedarraypool.calloc(); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `calloc` method is provided a first argument which is not a number... -{ - typedarraypool.calloc( 'abc' ); // $ExpectError - typedarraypool.calloc( true ); // $ExpectError - typedarraypool.calloc( false ); // $ExpectError - typedarraypool.calloc( null ); // $ExpectError - typedarraypool.calloc( {} ); // $ExpectError - typedarraypool.calloc( [] ); // $ExpectError - typedarraypool.calloc( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.calloc( 4, true ); // $ExpectError - typedarraypool.calloc( 4, false ); // $ExpectError - typedarraypool.calloc( 4, null ); // $ExpectError - typedarraypool.calloc( 4, 'abc' ); // $ExpectError - typedarraypool.calloc( 4, 123 ); // $ExpectError - typedarraypool.calloc( 4, [] ); // $ExpectError - typedarraypool.calloc( 4, {} ); // $ExpectError - typedarraypool.calloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided an incorrect number of arguments... -{ - typedarraypool.calloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `factory` method which returns a typed array pool.. -{ - typedarraypool.factory(); // $ExpectType Pool - typedarraypool.factory( { 'highWaterMark': 556 } ); // $ExpectType Pool -} - -// The compiler throws an error if the `factory` method is provided a `highWaterMark` option which is not a number... -{ - typedarraypool.factory( { 'highWaterMark': true } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': false } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': 'abc' } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': null } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': [] } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': {} } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an incorrect number of arguments... -{ - typedarraypool.factory( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` method which returns void... -{ - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.free( arr ); // $ExpectType void -} - -// The compiler throws an error if the `free` method is provided a first argument which is neither a typed array nor array buffer... -{ - typedarraypool.free( true ); // $ExpectError - typedarraypool.free( false ); // $ExpectError - typedarraypool.free( 123 ); // $ExpectError - typedarraypool.free( 'abc' ); // $ExpectError - typedarraypool.free( null ); // $ExpectError - typedarraypool.free( {} ); // $ExpectError - typedarraypool.free( ( x: number ): number => x ); // $ExpectError -} - -// Attached to the main export is a `clear` method which returns void... -{ - typedarraypool.clear(); // $ExpectType void -} - -// The compiler throws an error if the `clear` method is provided arguments... -{ - typedarraypool.clear( {} ); // $ExpectError - typedarraypool.clear( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `highWaterMark` property... -{ - typedarraypool.highWaterMark; // $ExpectType number -} - -// Attached to the main export is a `nbytes` property... -{ - typedarraypool.nbytes; // $ExpectType number -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 24a7846..0000000 --- a/examples/index.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 randu = require( '@stdlib/random-base-randu' ); -var typedarraypool = require( './../lib' ); - -// Create a typed array pool which can allocate at most 1GB: -var typedarray = typedarraypool.factory({ - 'highWaterMark': 1e9 -}); - -// Inspect the pool: -console.log( 'Max bytes: %d', typedarray.highWaterMark ); -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Allocate an array for storing double-precision floating-point numbers: -var arr1 = typedarray( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Fill the array... -var i; -for ( i = 0; i < arr1.length; i++ ) { - arr1[ i ] = randu(); -} - -// Inspect array contents: -console.log( arr1 ); - -// Free the array: -typedarray.free( arr1 ); - -// Allocate another array similar to the previous one: -var arr2 = typedarray( 5, 'float64' ); -// returns - -// Check that we have been returned a new typed array view: -console.log( arr2 === arr1 ); -// => false - -// Inspect array contents: -console.log( arr2 ); - -// Free the array: -typedarray.free( arr2 ); - -// Allocate an initialized array: -var arr3 = typedarray.calloc( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect array contents: -console.log( arr3 ); - -// Free the array: -typedarray.free( arr3 ); - -// Clear the pool: -typedarray.clear(); - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index de70cb0..c6a3785 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; import ArrayBuffer = require( '@stdlib/array-buffer' ); diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a7618a8 --- /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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.0-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessors@v0.0.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.1.0-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.1.0-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.1.0-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.1.0-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.1.0-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.0-esm/index.mjs";function k(e,t){return y(t)?w(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(c("01H2t,G9","highWaterMark",e.highWaterMark)):null:new TypeError(c("01H2V,FD",t))}function M(e){var t,r;for(t=[],r=0;rH.highWaterMark?null:(t=new j(e),w+=e,t)}function G(e,t,r){var s;return 0===t?new e(0):null===(s=F(u(t)*W[r]))?s:new e(s,0,t)}function K(){var e,i,n,l,j,v,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(n=d(i)))throw new TypeError(c("01H2Y,KZ",i));if(e<=0)return new n(0);if(r(arguments[0]))return G(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,m(l)?l=h(l,0):o(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=G(n,u,i)))return j;if(L(j)||T(j))return j.set(l),j;for(g=p(f(l)).accessors[0],v=p(i).accessors[1],b=0;b0){for(t=g(b(e.byteLength)),t=x(E.length-1,t),r=E[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '01H2Y,KZ', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = accessors( adtype( arr ) ).accessors[ 0 ];\n\t\t\tset = accessors( dtype ).accessors[ 1 ];\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '01H2r,N0', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( '01H2s,N1', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","accessors","adtype","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;ovEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,WAAY,gBAAiBP,EAAKI,gBAG3D,KARC,IAAIE,UAAWC,EAAQ,WAAYN,GAS5C,CC/BA,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,iHCaIG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EC/EO,CACNI,cAAiB,kBD+EbkB,UAAUC,SACdF,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOgB,EAAYC,EAAMC,EAAM1B,EAAKI,iBACpCgB,EAAS,EAETO,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB5B,EAAKI,eAC3C4B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOb,CACP,CASD,SAASc,EAAazB,GACrB,IAAI0B,EACAxB,EAMJ,OAHAA,EAAIe,EAAMjB,IAGDD,EAAKe,QAAUf,EAAMG,GAAIY,OAC1Bf,EAAMG,GAAIyB,MAGbhB,EAAOX,EAAIT,EAAKI,cACb,MAER+B,EAAM,IAAIE,EAAa5B,GAGvBW,GAAUX,EAEH0B,EACP,CAWD,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,EACzB,CAkBD,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAtB,EACAP,EACAmC,EACAC,EACAN,EACA7B,EAUJ,GALC8B,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAOzB,EAAO2B,IAEb,MAAM,IAAInC,UAAWC,EAAQ,WAAYkC,IAE1C,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKlC,EAAsBiB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAvB,EAAMK,UAAW,IACPC,OACL0B,EAAmBhC,GACvBA,EAAMiC,EAAgBjC,EAAK,GAChBkC,EAAkBlC,GAC7BA,EAAMmC,EAAenC,EAAK,GACf,WAAWoC,KAAMZ,KAE5BD,GAAO,GAGK,QADb9B,EAAM4B,EAAYC,EAAMC,EAAKC,IAE5B,OAAO/B,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAImC,IAAK5B,GACFP,EAKR,IAFAoC,EAAMQ,EAAWC,EAAQtC,IAAQqC,UAAW,GAC5CT,EAAMS,EAAWb,GAAQa,UAAW,GAC9B3C,EAAI,EAAGA,EAAI6B,EAAK7B,IACrBkC,EAAKnC,EAAKC,EAAGmC,EAAK7B,EAAKN,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,WAAYe,UAAW,IACpD,CAgBD,SAASO,IACR,IAAIe,EACAlC,EACA8C,EACA7C,EAUJ,GAAa,QANZD,EADc,KADfkC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCkC,EADItC,EAAiBR,GACfwC,EAAgBxC,EAAK,GAChBM,EAAgBN,GACrB0C,EAAe1C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAI6C,EAAIjC,OAAQZ,IAC5B6C,EAAK7C,GAAM,EAGb,OAAOD,CACP,CAcD,SAASoB,EAAMK,GACd,IAAI1B,EACAgD,EACA9C,EACJ,GAAK+C,EAAkBvB,IAASA,EAAIwB,OACnCxB,EAAMA,EAAIwB,YACJ,IAAMC,EAAezB,GAC3B,MAAM,IAAI7B,UAAWC,EAAQ,WAAY4B,IAE1C,GAAKA,EAAI0B,WAAa,EAAI,CAQzB,IAPApD,EAAIqD,EAAOpC,EAAMS,EAAI0B,aAGrBpD,EAAIsD,EAAKvD,EAAKe,OAAO,EAAGd,GAGxBgD,EAAIjD,EAAMC,GACJE,EAAI,EAAGA,EAAI8C,EAAElC,OAAQZ,IAC1B,GAAK8C,EAAG9C,KAAQwB,EACf,OAAO,EAITsB,EAAE7C,KAAMuB,EACR,CACD,OAAO,CACP,CAOD,SAASJ,IACR,IAAIpB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKe,OAAQZ,IAC7BH,EAAMG,GAAIY,OAAS,EAEpBH,EAAS,CACT,CACF,CEnTG,IAAC4C,EAAiB7C,ICPrBQ,EAAAsC,EAAA,UAAA9C"} \ No newline at end of file diff --git a/lib/bytes_per_element.json b/lib/bytes_per_element.json deleted file mode 100644 index f97fe70..0000000 --- a/lib/bytes_per_element.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "float64": 8, - "float32": 4, - "int16": 2, - "int32": 4, - "int8": 1, - "uint16": 2, - "uint32": 4, - "uint8": 1, - "uint8c": 1, - "complex64": 8, - "complex128": 16 -} diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index a421711..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +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'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'highWaterMark': 9007199254740992 - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index ae28056..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,370 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var isComplex64Array = require( '@stdlib/assert-is-complex64array' ); -var isComplex128Array = require( '@stdlib/assert-is-complex128array' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var ctors = require( '@stdlib/array-typed-ctors' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var accessors = require( '@stdlib/array-base-accessors' ); -var adtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil = require( '@stdlib/math-base-special-ceil' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); -var log2 = require( '@stdlib/math-base-special-log2' ); -var min = require( '@stdlib/math-base-special-min' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var createPool = require( './pool.js' ); -var BYTES_PER_ELEMENT = require( './bytes_per_element.json' ); - - -// VARIABLES // - -var Complex64Array = ctors( 'complex64' ); -var Complex128Array = ctors( 'complex128' ); - - -// FUNCTIONS // - -/** -* Tests whether an array is a single-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a single-precision complex floating-point number array -*/ -function isCmplx64Array( arr ) { - return ( arr instanceof Complex64Array ); -} - -/** -* Tests whether an array is a double-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a double-precision complex floating-point number array -*/ -function isCmplx128Array( arr ) { - return ( arr instanceof Complex128Array ); -} - - -// MAIN // - -/** -* Creates a typed array pool. -* -* @param {Options} [options] - pool options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} allocator -* -* @example -* var typedarraypool = factory(); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -function factory( options ) { - var nbytes; - var pool; - var opts; - var err; - - opts = defaults(); - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - pool = createPool( ceil( log2( opts.highWaterMark ) ) ); - nbytes = 0; - - setReadOnly( malloc, 'malloc', malloc ); // circular reference - setReadOnly( malloc, 'calloc', calloc ); - setReadOnly( malloc, 'free', free ); - setReadOnly( malloc, 'clear', clear ); - setReadOnly( malloc, 'highWaterMark', opts.highWaterMark ); - setReadOnlyAccessor( malloc, 'nbytes', getBytes ); - - return malloc; - - /** - * Returns the number of allocated bytes. - * - * @private - * @returns {NonNegativeInteger} number of allocated bytes - */ - function getBytes() { - return nbytes; - } - - /** - * Returns an array buffer. - * - * @private - * @param {NonNegativeInteger} n - number of bytes - * @returns {(ArrayBuffer|null)} array buffer or null - */ - function arraybuffer( n ) { - var buf; - var i; - - // Convert the number of bytes to an index in our pool table: - i = log2( n ); - - // If we already have an available array buffer, use it... - if ( i < pool.length && pool[ i ].length ) { - return pool[ i ].pop(); - } - // Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate... - if ( nbytes+n > opts.highWaterMark ) { - return null; - } - buf = new ArrayBuffer( n ); - - // Update the running counter of allocated bytes: - nbytes += n; - - return buf; - } - - /** - * Returns a typed array. - * - * @private - * @param {Function} ctor - typed array constructor - * @param {NonNegativeInteger} len - view length - * @param {string} dtype - data type - * @returns {(TypedArray|null)} typed array or null - */ - function typedarray( ctor, len, dtype ) { - var buf; - if ( len === 0 ) { - return new ctor( 0 ); - } - buf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] ); - if ( buf === null ) { - return buf; - } - return new ctor( buf, 0, len ); - } - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length or an array-like object - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function malloc() { - var nargs; - var dtype; - var ctor; - var arr; - var out; - var set; - var get; - var len; - var i; - - nargs = arguments.length; - if ( nargs && isString( arguments[ nargs-1 ] ) ) { - nargs -= 1; - dtype = arguments[ nargs ]; - } else { - dtype = 'float64'; - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( '01H2Y,KZ', dtype ) ); - } - if ( nargs <= 0 ) { - return new ctor( 0 ); - } - // Check if provided a typed array length... - if ( isNonNegativeInteger( arguments[ 0 ] ) ) { - return typedarray( ctor, arguments[ 0 ], dtype ); - } - // Check if provided an array-like object containing data elements... - if ( isCollection( arguments[ 0 ] ) ) { - arr = arguments[ 0 ]; - len = arr.length; - if ( isComplex128Array( arr ) ) { - arr = reinterpret128( arr, 0 ); - } else if ( isComplex64Array( arr ) ) { - arr = reinterpret64( arr, 0 ); - } else if ( /^complex/.test( dtype ) ) { - // Assume we've been provided an array of interleaved real and imaginary components... - len /= 2; - } - out = typedarray( ctor, len, dtype ); - if ( out === null ) { - return out; - } - if ( isCmplx128Array( out ) || isCmplx64Array( out ) ) { - out.set( arr ); - return out; - } - // Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other "unsafe" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things... - get = accessors( adtype( arr ) ).accessors[ 0 ]; - set = accessors( dtype ).accessors[ 1 ]; - for ( i = 0; i < len; i++ ) { - set( out, i, get( arr, i ) ); - } - return out; - } - throw new TypeError( format( '01H2r,N0', arguments[ 0 ] ) ); - } - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {NonNegativeInteger} [len=0] - array length - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function calloc() { - var nargs; - var out; - var tmp; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - out = malloc(); - } else if ( nargs === 1 ) { - out = malloc( arguments[ 0 ] ); - } else { - out = malloc( arguments[ 0 ], arguments[ 1 ] ); - } - if ( out !== null ) { - // Initialize the memory... - if ( isCmplx128Array( out ) ) { - tmp = reinterpret128( out, 0 ); - } else if ( isCmplx64Array( out ) ) { - tmp = reinterpret64( out, 0 ); - } else { - tmp = out; - } - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = 0.0; - } - } - return out; - } - - /** - * Frees a typed array or typed array buffer. - * - * ## Notes - * - * - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., "freeing" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool. - * - * @private - * @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free - * @throws {TypeError} must provide a typed array or typed array buffer - * @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed - */ - function free( buf ) { - var n; - var p; - var i; - if ( isTypedArrayLike( buf ) && buf.buffer ) { - buf = buf.buffer; - } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( '01H2s,N1', buf ) ); - } - if ( buf.byteLength > 0 ) { - n = floor( log2( buf.byteLength ) ); - - // Prohibit "freeing" array buffers which would potentially allow users to circumvent high water mark limits: - n = min( pool.length-1, n ); - - // Ensure that we do not attempt to free the same buffer more than once... - p = pool[ n ]; - for ( i = 0; i < p.length; i++ ) { - if ( p[ i ] === buf ) { - return false; - } - } - // Add the buffer to our pool of free buffers: - p.push( buf ); - } - return true; - } - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @private - */ - function clear() { - var i; - for ( i = 0; i < pool.length; i++ ) { - pool[ i ].length = 0; - } - nbytes = 0; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6c12a4e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Typed array pool. -* -* @module @stdlib/array-pool -* -* @example -* var typedarraypool = require( '@stdlib/array-pool' ); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8f69ee3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,63 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @name typedarraypool -* @type {Function} -* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a valid array length or an array-like object -* @throws {TypeError} must provide a recognized data type -* @returns {(TypedArray|null)} typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -var typedarraypool = factory(); - - -// EXPORTS // - -module.exports = typedarraypool; diff --git a/lib/pool.js b/lib/pool.js deleted file mode 100644 index 5abd287..0000000 --- a/lib/pool.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Initializes a cache for pooled typed array buffers. -* -* @private -* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size -* @returns {ArrayArray} initialized cache -*/ -function pool( n ) { - var out; - var i; - - out = []; - for ( i = 0; i < n+1; i++ ) { - out.push( [] ); - } - return out; -} - - -// EXPORTS // - -module.exports = pool; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 95667c7..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'highWaterMark': 1024 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '01H2V,FD', options ) ); - } - if ( hasOwnProp( options, 'highWaterMark' ) ) { - opts.highWaterMark = options.highWaterMark; - if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( '01H2t,G9', 'highWaterMark', opts.highWaterMark ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index f2284d8..bd7b179 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Typed array pool.", "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,76 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessors": "^0.1.0", - "@stdlib/array-buffer": "^0.1.0", - "@stdlib/array-dtype": "^0.1.0", - "@stdlib/array-typed-ctors": "^0.1.0", - "@stdlib/assert-has-own-property": "^0.1.0", - "@stdlib/assert-is-arraybuffer": "^0.1.0", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-complex128array": "^0.1.0", - "@stdlib/assert-is-complex64array": "^0.1.0", - "@stdlib/assert-is-nonnegative-integer": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.0", - "@stdlib/assert-is-string": "^0.1.0", - "@stdlib/assert-is-typed-array-like": "^0.1.0", - "@stdlib/math-base-special-ceil": "^0.1.0", - "@stdlib/math-base-special-ceil2": "^0.1.0", - "@stdlib/math-base-special-floor": "^0.1.0", - "@stdlib/math-base-special-log2": "^0.1.0", - "@stdlib/math-base-special-min": "^0.1.0", - "@stdlib/strided-base-reinterpret-complex128": "^0.1.0", - "@stdlib/strided-base-reinterpret-complex64": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.1.0", - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-float32": "^0.1.0", - "@stdlib/array-float64": "^0.1.0", - "@stdlib/array-int16": "^0.1.0", - "@stdlib/array-int32": "^0.1.0", - "@stdlib/array-int8": "^0.1.0", - "@stdlib/array-uint16": "^0.1.0", - "@stdlib/array-uint32": "^0.1.0", - "@stdlib/array-uint8": "^0.1.0", - "@stdlib/array-uint8c": "^0.1.0", - "@stdlib/assert-instance-of": "^0.1.0", - "@stdlib/assert-is-complex-typed-array": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.0", - "@stdlib/assert-is-typed-array": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/complex-float32": "^0.1.0", - "@stdlib/complex-float64": "^0.1.0", - "@stdlib/complex-imag": "^0.1.0", - "@stdlib/complex-imagf": "^0.1.0", - "@stdlib/complex-real": "^0.1.0", - "@stdlib/complex-realf": "^0.1.0", - "@stdlib/math-base-special-pow": "^0.1.0", - "@stdlib/random-base-randu": "^0.0.8", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..328ef03 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 396aee2..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,2240 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function (no options)', function test( t ) { - t.strictEqual( typeof factory(), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - t.strictEqual( typeof factory( {} ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided a `highWaterMark` option which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (length)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a function which returns a typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, length)', function test( t ) { - var typedarraypool = factory(); - var arr; - - arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a `malloc` method which is a circular reference', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - var buf; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the returned function is a property which returns the pool\'s high water mark', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function supports specifying a high water mark which limits the total amount of memory a pool can allocate', function test( t ) { - var typedarraypool; - var arr1; - var arr2; - - typedarraypool = factory({ - 'highWaterMark': 64 // bytes - }); - - typedarraypool.clear(); - - arr1 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr1.length, 8, 'returns expected value' ); - t.strictEqual( arr1.byteLength, 64, 'returns expected value' ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - typedarraypool.free( arr1 ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Create an array which is less than or equal to the high water mark: - arr2 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr2.length, 8, 'returns expected value' ); - t.strictEqual( arr2.byteLength, 64, 'returns expected value' ); - - typedarraypool.free( arr2 ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a property which returns the total number of accumulated bytes', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var typedarraypool; - var arrs; - var i; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 54aa5ee..0000000 --- a/test/test.js +++ /dev/null @@ -1,1797 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var typedarraypool = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -}); From f93305026608dbf5aa55735b9259aaac6aaa403d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 18:14:13 +0000 Subject: [PATCH 038/103] Update README.md for ESM bundle v0.1.0 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 99df702..41e0627 100644 --- a/README.md +++ b/README.md @@ -52,13 +52,13 @@ limitations under the License. ## Usage ```javascript -import typedarraypool from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-pool@esm/index.mjs'; +import typedarraypool from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-pool@v0.1.0-esm/index.mjs'; ``` You can also import the following named exports from the package: ```javascript -import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-pool@esm/index.mjs'; +import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-pool@v0.1.0-esm/index.mjs'; ``` #### typedarraypool( \[dtype] ) @@ -392,7 +392,7 @@ pool.free( arr ); - - - - From cd4978af8cf3b677e57cc0b996f37dbf3e64e637 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 3 Oct 2023 03:00:17 +0000 Subject: [PATCH 042/103] 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 | 43 +- benchmark/benchmark.calloc.js | 246 - benchmark/benchmark.factory.js | 71 - benchmark/benchmark.js | 246 - benchmark/benchmark.length.complex128.js | 102 - benchmark/benchmark.length.complex64.js | 102 - benchmark/benchmark.length.float32.js | 102 - benchmark/benchmark.length.float64.js | 102 - benchmark/benchmark.length.int16.js | 102 - benchmark/benchmark.length.int32.js | 102 - benchmark/benchmark.length.int8.js | 102 - benchmark/benchmark.length.uint16.js | 102 - benchmark/benchmark.length.uint32.js | 102 - benchmark/benchmark.length.uint8.js | 102 - benchmark/benchmark.length.uint8c.js | 102 - benchmark/benchmark.malloc.js | 246 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 347 -- docs/types/test.ts | 193 - examples/index.js | 80 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/bytes_per_element.json | 13 - lib/defaults.js | 42 - lib/factory.js | 370 -- lib/index.js | 56 - lib/main.js | 63 - lib/pool.js | 44 - lib/validate.js | 66 - package.json | 97 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 1797 ------ test/test.factory.js | 2240 -------- test/test.js | 1797 ------ 62 files changed, 6206 insertions(+), 12394 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.calloc.js delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.complex128.js delete mode 100644 benchmark/benchmark.length.complex64.js delete mode 100644 benchmark/benchmark.length.float32.js delete mode 100644 benchmark/benchmark.length.float64.js delete mode 100644 benchmark/benchmark.length.int16.js delete mode 100644 benchmark/benchmark.length.int32.js delete mode 100644 benchmark/benchmark.length.int8.js delete mode 100644 benchmark/benchmark.length.uint16.js delete mode 100644 benchmark/benchmark.length.uint32.js delete mode 100644 benchmark/benchmark.length.uint8.js delete mode 100644 benchmark/benchmark.length.uint8c.js delete mode 100644 benchmark/benchmark.malloc.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/bytes_per_element.json delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/pool.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index c1960e2..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-10-01T05:36:44.497Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ea35f20..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/array/pool) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6f7c875..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/array/pool) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 4f5a65c..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -493,7 +492,7 @@ console.log( 'nbytes: %d', typedarray.nbytes ); ## 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]. @@ -559,7 +558,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm diff --git a/benchmark/benchmark.calloc.js b/benchmark/benchmark.calloc.js deleted file mode 100644 index e5a1c77..0000000 --- a/benchmark/benchmark.calloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':calloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index f7cd676..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = typedarray.factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:highWaterMark', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'highWaterMark': 0 - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.highWaterMark = i; - f = typedarray.factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a023d2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.complex128.js b/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 47b623b..0000000 --- a/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex64.js b/benchmark/benchmark.length.complex64.js deleted file mode 100644 index 40a412b..0000000 --- a/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float32.js b/benchmark/benchmark.length.float32.js deleted file mode 100644 index 0227ed7..0000000 --- a/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float64.js b/benchmark/benchmark.length.float64.js deleted file mode 100644 index 2dbac1c..0000000 --- a/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int16.js b/benchmark/benchmark.length.int16.js deleted file mode 100644 index e2a8adc..0000000 --- a/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int32.js b/benchmark/benchmark.length.int32.js deleted file mode 100644 index e4df0aa..0000000 --- a/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int8.js b/benchmark/benchmark.length.int8.js deleted file mode 100644 index 7ceac11..0000000 --- a/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint16.js b/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 9a532b6..0000000 --- a/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint32.js b/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 98f2d7f..0000000 --- a/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8.js b/benchmark/benchmark.length.uint8.js deleted file mode 100644 index 8359249..0000000 --- a/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8c.js b/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index d47d023..0000000 --- a/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.malloc.js b/benchmark/benchmark.malloc.js deleted file mode 100644 index d4eea72..0000000 --- a/benchmark/benchmark.malloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':malloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 9689761..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/array/pool" -%% click B href "https://github.com/stdlib-js/array-pool/tree/main" -%% click C href "https://github.com/stdlib-js/array-pool/tree/production" -%% click D href "https://github.com/stdlib-js/array-pool/tree/esm" -%% click E href "https://github.com/stdlib-js/array-pool/tree/deno" -%% click F href "https://github.com/stdlib-js/array-pool/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/pool -[production-url]: https://github.com/stdlib-js/array-pool/tree/production -[deno-url]: https://github.com/stdlib-js/array-pool/tree/deno -[umd-url]: https://github.com/stdlib-js/array-pool/tree/umd -[esm-url]: https://github.com/stdlib-js/array-pool/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 5160b6f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import typedarraypool from '../docs/types/index'; -export = typedarraypool; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 9d31d69..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var l=function(n,i){return function(){return i||n((i={exports:{}}).exports,i),i.exports}};var k=l(function(kr,M){ -function D(){return{highWaterMark:9007199254740992}}M.exports=D -});var E=l(function(Ar,W){ -var G=require('@stdlib/assert-is-plain-object/dist'),H=require('@stdlib/assert-has-own-property/dist'),J=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,A=require('@stdlib/error-tools-fmtprodmsg/dist');function K(n,i){return G(i)?H(i,"highWaterMark")&&(n.highWaterMark=i.highWaterMark,!J(n.highWaterMark))?new TypeError(A('01H2t',"highWaterMark",n.highWaterMark)):null:new TypeError(A('01H2V',i));}W.exports=K -});var C=l(function(Wr,T){ -function Q(n){var i,u;for(i=[],u=0;uv.highWaterMark?null:(e=new ur(r),i+=r,e)}function d(r,e,t){var a;return e===0?new r(0):(a=_(lr(e)*hr[t]),a===null?a:new r(a,0,e))}function s(){var r,e,t,a,o,x,w,c,f;if(r=arguments.length,r&&X(arguments[r-1])?(r-=1,e=arguments[r]):e="float64",t=y(e),t===null)throw new TypeError(m('01H2Y',e));if(r<=0)return new t(0);if(Z(arguments[0]))return d(t,arguments[0],e);if($(arguments[0])){if(a=arguments[0],c=a.length,tr(a)?a=P(a,0):ar(a)?a=b(a,0):/^complex/.test(e)&&(c/=2),o=d(t,c,e),o===null)return o;if(L(o)||N(o))return o.set(a),o;for(w=B(nr(a)).accessors[0],x=B(e).accessors[1],f=0;f0){for(e=or(p(r.byteLength)),e=vr(u.length-1,e),t=u[e],a=0;a[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = accessors( adtype( arr ) ).accessors[ 0 ];\n\t\t\tset = accessors( dtype ).accessors[ 1 ];\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nmodule.exports = typedarraypool;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* var typedarraypool = require( '@stdlib/array-pool' );\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,cAAiB,gBAClB,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,eAAgB,IACzCD,EAAK,cAAgBC,EAAQ,cACxB,CAACJ,EAAsBG,EAAK,aAAc,GACvC,IAAI,UAAWF,EAAQ,2EAA4E,gBAAiBE,EAAK,aAAc,CAAE,EAG3I,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cA6BA,SAASC,EAAM,EAAI,CAClB,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAI,EAAE,EAAGA,IACrBD,EAAI,KAAM,CAAC,CAAE,EAEd,OAAOA,CACR,CAKAF,EAAO,QAAUC,IC3CjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,QAAW,EACX,QAAW,EACX,MAAS,EACT,MAAS,EACT,KAAQ,EACR,OAAU,EACV,OAAU,EACV,MAAS,EACT,OAAU,EACT,UAAa,EACb,WAAc,EAChB,ICZA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAe,QAAS,8BAA+B,EACvDC,GAAmB,QAAS,oCAAqC,EACjEC,GAAgB,QAAS,+BAAgC,EACzDC,GAAmB,QAAS,kCAAmC,EAC/DC,GAAoB,QAAS,mCAAoC,EACjEC,EAAc,QAAS,uDAAwD,EAC/EC,GAAsB,QAAS,uDAAwD,EACvFC,EAAQ,QAAS,2BAA4B,EAC7CC,EAAgB,QAAS,4CAA6C,EACtEC,EAAiB,QAAS,6CAA8C,EACxEC,EAAY,QAAS,8BAA+B,EACpDC,GAAS,QAAS,qBAAsB,EACxCC,EAAS,QAAS,uBAAwB,EAC1CC,GAAc,QAAS,sBAAuB,EAC9CC,GAAO,QAAS,gCAAiC,EACjDC,GAAQ,QAAS,iCAAkC,EACnDC,GAAQ,QAAS,iCAAkC,EACnDC,EAAO,QAAS,gCAAiC,EACjDC,GAAM,QAAS,+BAAgC,EAC/CC,GAAW,IACXC,GAAW,IACXC,GAAa,IACbC,GAAoB,IAKpBC,GAAiBhB,EAAO,WAAY,EACpCiB,GAAkBjB,EAAO,YAAa,EAY1C,SAASkB,EAAgBC,EAAM,CAC9B,OAASA,aAAeH,EACzB,CASA,SAASI,EAAiBD,EAAM,CAC/B,OAASA,aAAeF,EACzB,CA6BA,SAASI,GAASC,EAAU,CAC3B,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,EAAOb,GAAS,EACX,UAAU,SACdc,EAAMb,GAAUY,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAAF,EAAOV,GAAYP,GAAMG,EAAMe,EAAK,aAAc,CAAE,CAAE,EACtDF,EAAS,EAETzB,EAAa6B,EAAQ,SAAUA,CAAO,EACtC7B,EAAa6B,EAAQ,SAAUC,CAAO,EACtC9B,EAAa6B,EAAQ,OAAQE,CAAK,EAClC/B,EAAa6B,EAAQ,QAASG,CAAM,EACpChC,EAAa6B,EAAQ,gBAAiBF,EAAK,aAAc,EACzD1B,GAAqB4B,EAAQ,SAAUI,CAAS,EAEzCJ,EAQP,SAASI,GAAW,CACnB,OAAOR,CACR,CASA,SAASS,EAAaC,EAAI,CACzB,IAAIC,EACAC,EAMJ,OAHAA,EAAIzB,EAAMuB,CAAE,EAGPE,EAAIX,EAAK,QAAUA,EAAMW,CAAE,EAAE,OAC1BX,EAAMW,CAAE,EAAE,IAAI,EAGjBZ,EAAOU,EAAIR,EAAK,cACb,MAERS,EAAM,IAAI5B,GAAa2B,CAAE,EAGzBV,GAAUU,EAEHC,EACR,CAWA,SAASE,EAAYC,EAAMC,EAAKC,EAAQ,CACvC,IAAIL,EACJ,OAAKI,IAAQ,EACL,IAAID,EAAM,CAAE,GAEpBH,EAAMF,EAAavB,GAAO6B,CAAI,EAAEvB,GAAmBwB,CAAM,CAAE,EACtDL,IAAQ,KACLA,EAED,IAAIG,EAAMH,EAAK,EAAGI,CAAI,EAC9B,CAkBA,SAASX,GAAS,CACjB,IAAIa,EACAD,EACAF,EACAlB,EACAsB,EACAC,EACAC,EACAL,EACAH,EAUJ,GARAK,EAAQ,UAAU,OACbA,GAASjD,EAAU,UAAWiD,EAAM,CAAE,CAAE,GAC5CA,GAAS,EACTD,EAAQ,UAAWC,CAAM,GAEzBD,EAAQ,UAETF,EAAOrC,EAAOuC,CAAM,EACfF,IAAS,KACb,MAAM,IAAI,UAAWhC,EAAQ,sEAAuEkC,CAAM,CAAE,EAE7G,GAAKC,GAAS,EACb,OAAO,IAAIH,EAAM,CAAE,EAGpB,GAAK7C,EAAsB,UAAW,CAAE,CAAE,EACzC,OAAO4C,EAAYC,EAAM,UAAW,CAAE,EAAGE,CAAM,EAGhD,GAAK9C,EAAc,UAAW,CAAE,CAAE,EAAI,CAYrC,GAXA0B,EAAM,UAAW,CAAE,EACnBmB,EAAMnB,EAAI,OACLtB,GAAmBsB,CAAI,EAC3BA,EAAMjB,EAAgBiB,EAAK,CAAE,EAClBvB,GAAkBuB,CAAI,EACjCA,EAAMlB,EAAekB,EAAK,CAAE,EACjB,WAAW,KAAMoB,CAAM,IAElCD,GAAO,GAERG,EAAML,EAAYC,EAAMC,EAAKC,CAAM,EAC9BE,IAAQ,KACZ,OAAOA,EAER,GAAKrB,EAAiBqB,CAAI,GAAKvB,EAAgBuB,CAAI,EAClD,OAAAA,EAAI,IAAKtB,CAAI,EACNsB,EAKR,IAFAE,EAAMxC,EAAWC,GAAQe,CAAI,CAAE,EAAE,UAAW,CAAE,EAC9CuB,EAAMvC,EAAWoC,CAAM,EAAE,UAAW,CAAE,EAChCJ,EAAI,EAAGA,EAAIG,EAAKH,IACrBO,EAAKD,EAAKN,EAAGQ,EAAKxB,EAAKgB,CAAE,CAAE,EAE5B,OAAOM,CACR,CACA,MAAM,IAAI,UAAWpC,EAAQ,wGAAyG,UAAW,CAAE,CAAE,CAAE,CACxJ,CAgBA,SAASuB,GAAS,CACjB,IAAIY,EACAC,EACAG,EACAT,EAUJ,GARAK,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAMd,EAAO,EACFa,IAAU,EACrBC,EAAMd,EAAQ,UAAW,CAAE,CAAE,EAE7Bc,EAAMd,EAAQ,UAAW,CAAE,EAAG,UAAW,CAAE,CAAE,EAEzCc,IAAQ,KASZ,IAPKrB,EAAiBqB,CAAI,EACzBG,EAAM1C,EAAgBuC,EAAK,CAAE,EAClBvB,EAAgBuB,CAAI,EAC/BG,EAAM3C,EAAewC,EAAK,CAAE,EAE5BG,EAAMH,EAEDN,EAAI,EAAGA,EAAIS,EAAI,OAAQT,IAC5BS,EAAKT,CAAE,EAAI,EAGb,OAAOM,CACR,CAcA,SAASZ,EAAMK,EAAM,CACpB,IAAID,EACAY,EACAV,EACJ,GAAKzC,GAAkBwC,CAAI,GAAKA,EAAI,OACnCA,EAAMA,EAAI,eACC,CAACvC,GAAeuC,CAAI,EAC/B,MAAM,IAAI,UAAW7B,EAAQ,4EAA6E6B,CAAI,CAAE,EAEjH,GAAKA,EAAI,WAAa,EAAI,CAQzB,IAPAD,EAAIzB,GAAOE,EAAMwB,EAAI,UAAW,CAAE,EAGlCD,EAAItB,GAAKa,EAAK,OAAO,EAAGS,CAAE,EAG1BY,EAAIrB,EAAMS,CAAE,EACNE,EAAI,EAAGA,EAAIU,EAAE,OAAQV,IAC1B,GAAKU,EAAGV,CAAE,IAAMD,EACf,MAAO,GAITW,EAAE,KAAMX,CAAI,CACb,CACA,MAAO,EACR,CAOA,SAASJ,GAAQ,CAChB,IAAIK,EACJ,IAAMA,EAAI,EAAGA,EAAIX,EAAK,OAAQW,IAC7BX,EAAMW,CAAE,EAAE,OAAS,EAEpBZ,EAAS,CACV,CACD,CAKAjC,EAAO,QAAU+B,KCjXjB,IAAAyB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAU,IAmCVC,GAAiBD,GAAQ,EAK7BD,EAAO,QAAUE,KCnBjB,IAAIC,GAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,GAAU,IAKdF,GAAaC,EAAM,UAAWC,EAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isNonNegativeInteger", "format", "validate", "opts", "options", "require_pool", "__commonJSMin", "exports", "module", "pool", "out", "i", "require_bytes_per_element", "__commonJSMin", "exports", "module", "require_factory", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isCollection", "isTypedArrayLike", "isArrayBuffer", "isComplex64Array", "isComplex128Array", "setReadOnly", "setReadOnlyAccessor", "ctors", "reinterpret64", "reinterpret128", "accessors", "adtype", "format", "ArrayBuffer", "ceil", "floor", "ceil2", "log2", "min", "defaults", "validate", "createPool", "BYTES_PER_ELEMENT", "Complex64Array", "Complex128Array", "isCmplx64Array", "arr", "isCmplx128Array", "factory", "options", "nbytes", "pool", "opts", "err", "malloc", "calloc", "free", "clear", "getBytes", "arraybuffer", "n", "buf", "i", "typedarray", "ctor", "len", "dtype", "nargs", "out", "set", "get", "tmp", "p", "require_main", "__commonJSMin", "exports", "module", "factory", "typedarraypool", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5244595..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,347 +0,0 @@ - -{{alias}}( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - Memory is **uninitialized**, which means that the contents of a returned - typed array may contain sensitive contents. - - The function supports the following data types: - - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - The default typed array data type is `float64`. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}() - [] - > arr = {{alias}}( 'float32' ) - [] - - -{{alias}}( length[, dtype] ) - Returns an uninitialized typed array having a specified length from a typed - array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > arr = {{alias}}( 5, 'int32' ) - - - -{{alias}}( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - This method shares the same security vulnerabilities mentioned above. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc() - - > arr = {{alias}}.malloc( 'float32' ) - - - -{{alias}}.malloc( length[, dtype] ) - Returns a typed array having a specified length from a typed array memory - pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc( 5 ) - - > arr = {{alias}}.malloc( 5, 'int32' ) - - - -{{alias}}.malloc( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}.malloc( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.calloc( [dtype] ) - Returns a zero-initialized typed array from a typed array memory pool. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc() - [] - > arr = {{alias}}.calloc( 'float32' ) - [] - - -{{alias}}.calloc( length[, dtype] ) - Returns a zero-initialized typed array having a specified length from a - typed array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}.calloc( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}.free( buf ) - Frees a typed array or typed array buffer for use in a future allocation. - - Parameters - ---------- - buf: TypedArray|ArrayBuffer - Typed array or typed array buffer to free. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ) - - -{{alias}}.clear() - Clears the typed array pool allowing garbage collection of previously - allocated (and currently free) array buffers. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - > {{alias}}.clear() - - -{{alias}}.highWaterMark - Read-only property returning the pool's high water mark. - - Once a high water mark is reached, typed array allocation fails. - - Examples - -------- - > {{alias}}.highWaterMark - - -{{alias}}.nbytes - Read-only property returning the total number of allocated bytes. - - The returned value is the total accumulated value. Hence, anytime a pool - must allocate a new array buffer (i.e., more memory), the pool increments - this value. - - The only time this value is decremented is when a pool is cleared. - - This behavior means that, while allocated buffers which are never freed may, - in fact, be garbage collected, they continue to count against the high water - mark limit. - - Accordingly, you should *always* free allocated buffers in order to prevent - the pool from believing that non-freed buffers are continually in use. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.nbytes - - -{{alias}}.factory( [options] ) - Creates a typed array pool. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.highWaterMark: integer (optional) - Maximum total memory (in bytes) which can be allocated. - - Returns - ------- - fcn: Function - Function for creating typed arrays from a typed array memory pool. - - Examples - -------- - > var pool = {{alias}}.factory(); - > var arr1 = pool( 3, 'float64' ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1014bba..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,193 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-empty */ -/* tslint:disable:no-unused-expression */ - -import typedarraypool = require( './index' ); - - -// TESTS // - -// The function returns a typed array or null... -{ - typedarraypool(); // $ExpectType TypedArrayOrNull - typedarraypool( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the function is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool( true ); // $ExpectError - typedarraypool( false ); // $ExpectError - typedarraypool( null ); // $ExpectError - typedarraypool( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized data type... -{ - typedarraypool( 4, true ); // $ExpectError - typedarraypool( 4, false ); // $ExpectError - typedarraypool( 4, null ); // $ExpectError - typedarraypool( 4, 'abc' ); // $ExpectError - typedarraypool( 4, 123 ); // $ExpectError - typedarraypool( 4, [] ); // $ExpectError - typedarraypool( 4, {} ); // $ExpectError - typedarraypool( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an incorrect number of arguments... -{ - typedarraypool( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `malloc` method which returns a typed array or null... -{ - typedarraypool.malloc(); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.malloc( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `malloc` method is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool.malloc( true ); // $ExpectError - typedarraypool.malloc( false ); // $ExpectError - typedarraypool.malloc( null ); // $ExpectError - typedarraypool.malloc( {} ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.malloc( 4, true ); // $ExpectError - typedarraypool.malloc( 4, false ); // $ExpectError - typedarraypool.malloc( 4, null ); // $ExpectError - typedarraypool.malloc( 4, 'abc' ); // $ExpectError - typedarraypool.malloc( 4, 123 ); // $ExpectError - typedarraypool.malloc( 4, [] ); // $ExpectError - typedarraypool.malloc( 4, {} ); // $ExpectError - typedarraypool.malloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided an incorrect number of arguments... -{ - typedarraypool.malloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `calloc` method which returns a typed array or null... -{ - typedarraypool.calloc(); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `calloc` method is provided a first argument which is not a number... -{ - typedarraypool.calloc( 'abc' ); // $ExpectError - typedarraypool.calloc( true ); // $ExpectError - typedarraypool.calloc( false ); // $ExpectError - typedarraypool.calloc( null ); // $ExpectError - typedarraypool.calloc( {} ); // $ExpectError - typedarraypool.calloc( [] ); // $ExpectError - typedarraypool.calloc( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.calloc( 4, true ); // $ExpectError - typedarraypool.calloc( 4, false ); // $ExpectError - typedarraypool.calloc( 4, null ); // $ExpectError - typedarraypool.calloc( 4, 'abc' ); // $ExpectError - typedarraypool.calloc( 4, 123 ); // $ExpectError - typedarraypool.calloc( 4, [] ); // $ExpectError - typedarraypool.calloc( 4, {} ); // $ExpectError - typedarraypool.calloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided an incorrect number of arguments... -{ - typedarraypool.calloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `factory` method which returns a typed array pool.. -{ - typedarraypool.factory(); // $ExpectType Pool - typedarraypool.factory( { 'highWaterMark': 556 } ); // $ExpectType Pool -} - -// The compiler throws an error if the `factory` method is provided a `highWaterMark` option which is not a number... -{ - typedarraypool.factory( { 'highWaterMark': true } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': false } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': 'abc' } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': null } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': [] } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': {} } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an incorrect number of arguments... -{ - typedarraypool.factory( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` method which returns void... -{ - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.free( arr ); // $ExpectType void -} - -// The compiler throws an error if the `free` method is provided a first argument which is neither a typed array nor array buffer... -{ - typedarraypool.free( true ); // $ExpectError - typedarraypool.free( false ); // $ExpectError - typedarraypool.free( 123 ); // $ExpectError - typedarraypool.free( 'abc' ); // $ExpectError - typedarraypool.free( null ); // $ExpectError - typedarraypool.free( {} ); // $ExpectError - typedarraypool.free( ( x: number ): number => x ); // $ExpectError -} - -// Attached to the main export is a `clear` method which returns void... -{ - typedarraypool.clear(); // $ExpectType void -} - -// The compiler throws an error if the `clear` method is provided arguments... -{ - typedarraypool.clear( {} ); // $ExpectError - typedarraypool.clear( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `highWaterMark` property... -{ - typedarraypool.highWaterMark; // $ExpectType number -} - -// Attached to the main export is a `nbytes` property... -{ - typedarraypool.nbytes; // $ExpectType number -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 24a7846..0000000 --- a/examples/index.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 randu = require( '@stdlib/random-base-randu' ); -var typedarraypool = require( './../lib' ); - -// Create a typed array pool which can allocate at most 1GB: -var typedarray = typedarraypool.factory({ - 'highWaterMark': 1e9 -}); - -// Inspect the pool: -console.log( 'Max bytes: %d', typedarray.highWaterMark ); -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Allocate an array for storing double-precision floating-point numbers: -var arr1 = typedarray( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Fill the array... -var i; -for ( i = 0; i < arr1.length; i++ ) { - arr1[ i ] = randu(); -} - -// Inspect array contents: -console.log( arr1 ); - -// Free the array: -typedarray.free( arr1 ); - -// Allocate another array similar to the previous one: -var arr2 = typedarray( 5, 'float64' ); -// returns - -// Check that we have been returned a new typed array view: -console.log( arr2 === arr1 ); -// => false - -// Inspect array contents: -console.log( arr2 ); - -// Free the array: -typedarray.free( arr2 ); - -// Allocate an initialized array: -var arr3 = typedarray.calloc( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect array contents: -console.log( arr3 ); - -// Free the array: -typedarray.free( arr3 ); - -// Clear the pool: -typedarray.clear(); - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index de70cb0..c6a3785 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; import ArrayBuffer = require( '@stdlib/array-buffer' ); diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9b88f36 --- /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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.0-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessors@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.1.0-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.1.0-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.1.0-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.1.0-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.1.0-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.0-esm/index.mjs";function k(e,t){return y(t)?w(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(c("01H2t,G9","highWaterMark",e.highWaterMark)):null:new TypeError(c("01H2V,FD",t))}function M(e){var t,r;for(t=[],r=0;rH.highWaterMark?null:(t=new j(e),w+=e,t)}function G(e,t,r){var s;return 0===t?new e(0):null===(s=F(u(t)*W[r]))?s:new e(s,0,t)}function K(){var e,i,n,l,j,v,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(n=d(i)))throw new TypeError(c("01H2Y,KZ",i));if(e<=0)return new n(0);if(r(arguments[0]))return G(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,m(l)?l=h(l,0):o(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=G(n,u,i)))return j;if(L(j)||T(j))return j.set(l),j;for(g=p(f(l)).accessors[0],v=p(i).accessors[1],b=0;b0){for(t=g(b(e.byteLength)),t=x(E.length-1,t),r=E[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '01H2Y,KZ', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = accessors( adtype( arr ) ).accessors[ 0 ];\n\t\t\tset = accessors( dtype ).accessors[ 1 ];\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '01H2r,N0', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( '01H2s,N1', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","accessors","adtype","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;ywEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,WAAY,gBAAiBP,EAAKI,gBAG3D,KARC,IAAIE,UAAWC,EAAQ,WAAYN,GAS5C,CC/BA,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,iHCaIG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EC/EO,CACNI,cAAiB,kBD+EbkB,UAAUC,SACdF,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOgB,EAAYC,EAAMC,EAAM1B,EAAKI,iBACpCgB,EAAS,EAETO,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB5B,EAAKI,eAC3C4B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOb,CACP,CASD,SAASc,EAAazB,GACrB,IAAI0B,EACAxB,EAMJ,OAHAA,EAAIe,EAAMjB,IAGDD,EAAKe,QAAUf,EAAMG,GAAIY,OAC1Bf,EAAMG,GAAIyB,MAGbhB,EAAOX,EAAIT,EAAKI,cACb,MAER+B,EAAM,IAAIE,EAAa5B,GAGvBW,GAAUX,EAEH0B,EACP,CAWD,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,EACzB,CAkBD,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAtB,EACAP,EACAmC,EACAC,EACAN,EACA7B,EAUJ,GALC8B,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAOzB,EAAO2B,IAEb,MAAM,IAAInC,UAAWC,EAAQ,WAAYkC,IAE1C,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKlC,EAAsBiB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAvB,EAAMK,UAAW,IACPC,OACL0B,EAAmBhC,GACvBA,EAAMiC,EAAgBjC,EAAK,GAChBkC,EAAkBlC,GAC7BA,EAAMmC,EAAenC,EAAK,GACf,WAAWoC,KAAMZ,KAE5BD,GAAO,GAGK,QADb9B,EAAM4B,EAAYC,EAAMC,EAAKC,IAE5B,OAAO/B,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAImC,IAAK5B,GACFP,EAKR,IAFAoC,EAAMQ,EAAWC,EAAQtC,IAAQqC,UAAW,GAC5CT,EAAMS,EAAWb,GAAQa,UAAW,GAC9B3C,EAAI,EAAGA,EAAI6B,EAAK7B,IACrBkC,EAAKnC,EAAKC,EAAGmC,EAAK7B,EAAKN,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,WAAYe,UAAW,IACpD,CAgBD,SAASO,IACR,IAAIe,EACAlC,EACA8C,EACA7C,EAUJ,GAAa,QANZD,EADc,KADfkC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCkC,EADItC,EAAiBR,GACfwC,EAAgBxC,EAAK,GAChBM,EAAgBN,GACrB0C,EAAe1C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAI6C,EAAIjC,OAAQZ,IAC5B6C,EAAK7C,GAAM,EAGb,OAAOD,CACP,CAcD,SAASoB,EAAMK,GACd,IAAI1B,EACAgD,EACA9C,EACJ,GAAK+C,EAAkBvB,IAASA,EAAIwB,OACnCxB,EAAMA,EAAIwB,YACJ,IAAMC,EAAezB,GAC3B,MAAM,IAAI7B,UAAWC,EAAQ,WAAY4B,IAE1C,GAAKA,EAAI0B,WAAa,EAAI,CAQzB,IAPApD,EAAIqD,EAAOpC,EAAMS,EAAI0B,aAGrBpD,EAAIsD,EAAKvD,EAAKe,OAAO,EAAGd,GAGxBgD,EAAIjD,EAAMC,GACJE,EAAI,EAAGA,EAAI8C,EAAElC,OAAQZ,IAC1B,GAAK8C,EAAG9C,KAAQwB,EACf,OAAO,EAITsB,EAAE7C,KAAMuB,EACR,CACD,OAAO,CACP,CAOD,SAASJ,IACR,IAAIpB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKe,OAAQZ,IAC7BH,EAAMG,GAAIY,OAAS,EAEpBH,EAAS,CACT,CACF,CEnTG,IAAC4C,EAAiB7C,ICPrBQ,EAAAsC,EAAA,UAAA9C"} \ No newline at end of file diff --git a/lib/bytes_per_element.json b/lib/bytes_per_element.json deleted file mode 100644 index f97fe70..0000000 --- a/lib/bytes_per_element.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "float64": 8, - "float32": 4, - "int16": 2, - "int32": 4, - "int8": 1, - "uint16": 2, - "uint32": 4, - "uint8": 1, - "uint8c": 1, - "complex64": 8, - "complex128": 16 -} diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index a421711..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +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'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'highWaterMark': 9007199254740992 - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index ae28056..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,370 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var isComplex64Array = require( '@stdlib/assert-is-complex64array' ); -var isComplex128Array = require( '@stdlib/assert-is-complex128array' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var ctors = require( '@stdlib/array-typed-ctors' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var accessors = require( '@stdlib/array-base-accessors' ); -var adtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil = require( '@stdlib/math-base-special-ceil' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); -var log2 = require( '@stdlib/math-base-special-log2' ); -var min = require( '@stdlib/math-base-special-min' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var createPool = require( './pool.js' ); -var BYTES_PER_ELEMENT = require( './bytes_per_element.json' ); - - -// VARIABLES // - -var Complex64Array = ctors( 'complex64' ); -var Complex128Array = ctors( 'complex128' ); - - -// FUNCTIONS // - -/** -* Tests whether an array is a single-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a single-precision complex floating-point number array -*/ -function isCmplx64Array( arr ) { - return ( arr instanceof Complex64Array ); -} - -/** -* Tests whether an array is a double-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a double-precision complex floating-point number array -*/ -function isCmplx128Array( arr ) { - return ( arr instanceof Complex128Array ); -} - - -// MAIN // - -/** -* Creates a typed array pool. -* -* @param {Options} [options] - pool options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} allocator -* -* @example -* var typedarraypool = factory(); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -function factory( options ) { - var nbytes; - var pool; - var opts; - var err; - - opts = defaults(); - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - pool = createPool( ceil( log2( opts.highWaterMark ) ) ); - nbytes = 0; - - setReadOnly( malloc, 'malloc', malloc ); // circular reference - setReadOnly( malloc, 'calloc', calloc ); - setReadOnly( malloc, 'free', free ); - setReadOnly( malloc, 'clear', clear ); - setReadOnly( malloc, 'highWaterMark', opts.highWaterMark ); - setReadOnlyAccessor( malloc, 'nbytes', getBytes ); - - return malloc; - - /** - * Returns the number of allocated bytes. - * - * @private - * @returns {NonNegativeInteger} number of allocated bytes - */ - function getBytes() { - return nbytes; - } - - /** - * Returns an array buffer. - * - * @private - * @param {NonNegativeInteger} n - number of bytes - * @returns {(ArrayBuffer|null)} array buffer or null - */ - function arraybuffer( n ) { - var buf; - var i; - - // Convert the number of bytes to an index in our pool table: - i = log2( n ); - - // If we already have an available array buffer, use it... - if ( i < pool.length && pool[ i ].length ) { - return pool[ i ].pop(); - } - // Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate... - if ( nbytes+n > opts.highWaterMark ) { - return null; - } - buf = new ArrayBuffer( n ); - - // Update the running counter of allocated bytes: - nbytes += n; - - return buf; - } - - /** - * Returns a typed array. - * - * @private - * @param {Function} ctor - typed array constructor - * @param {NonNegativeInteger} len - view length - * @param {string} dtype - data type - * @returns {(TypedArray|null)} typed array or null - */ - function typedarray( ctor, len, dtype ) { - var buf; - if ( len === 0 ) { - return new ctor( 0 ); - } - buf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] ); - if ( buf === null ) { - return buf; - } - return new ctor( buf, 0, len ); - } - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length or an array-like object - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function malloc() { - var nargs; - var dtype; - var ctor; - var arr; - var out; - var set; - var get; - var len; - var i; - - nargs = arguments.length; - if ( nargs && isString( arguments[ nargs-1 ] ) ) { - nargs -= 1; - dtype = arguments[ nargs ]; - } else { - dtype = 'float64'; - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( '01H2Y,KZ', dtype ) ); - } - if ( nargs <= 0 ) { - return new ctor( 0 ); - } - // Check if provided a typed array length... - if ( isNonNegativeInteger( arguments[ 0 ] ) ) { - return typedarray( ctor, arguments[ 0 ], dtype ); - } - // Check if provided an array-like object containing data elements... - if ( isCollection( arguments[ 0 ] ) ) { - arr = arguments[ 0 ]; - len = arr.length; - if ( isComplex128Array( arr ) ) { - arr = reinterpret128( arr, 0 ); - } else if ( isComplex64Array( arr ) ) { - arr = reinterpret64( arr, 0 ); - } else if ( /^complex/.test( dtype ) ) { - // Assume we've been provided an array of interleaved real and imaginary components... - len /= 2; - } - out = typedarray( ctor, len, dtype ); - if ( out === null ) { - return out; - } - if ( isCmplx128Array( out ) || isCmplx64Array( out ) ) { - out.set( arr ); - return out; - } - // Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other "unsafe" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things... - get = accessors( adtype( arr ) ).accessors[ 0 ]; - set = accessors( dtype ).accessors[ 1 ]; - for ( i = 0; i < len; i++ ) { - set( out, i, get( arr, i ) ); - } - return out; - } - throw new TypeError( format( '01H2r,N0', arguments[ 0 ] ) ); - } - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {NonNegativeInteger} [len=0] - array length - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function calloc() { - var nargs; - var out; - var tmp; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - out = malloc(); - } else if ( nargs === 1 ) { - out = malloc( arguments[ 0 ] ); - } else { - out = malloc( arguments[ 0 ], arguments[ 1 ] ); - } - if ( out !== null ) { - // Initialize the memory... - if ( isCmplx128Array( out ) ) { - tmp = reinterpret128( out, 0 ); - } else if ( isCmplx64Array( out ) ) { - tmp = reinterpret64( out, 0 ); - } else { - tmp = out; - } - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = 0.0; - } - } - return out; - } - - /** - * Frees a typed array or typed array buffer. - * - * ## Notes - * - * - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., "freeing" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool. - * - * @private - * @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free - * @throws {TypeError} must provide a typed array or typed array buffer - * @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed - */ - function free( buf ) { - var n; - var p; - var i; - if ( isTypedArrayLike( buf ) && buf.buffer ) { - buf = buf.buffer; - } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( '01H2s,N1', buf ) ); - } - if ( buf.byteLength > 0 ) { - n = floor( log2( buf.byteLength ) ); - - // Prohibit "freeing" array buffers which would potentially allow users to circumvent high water mark limits: - n = min( pool.length-1, n ); - - // Ensure that we do not attempt to free the same buffer more than once... - p = pool[ n ]; - for ( i = 0; i < p.length; i++ ) { - if ( p[ i ] === buf ) { - return false; - } - } - // Add the buffer to our pool of free buffers: - p.push( buf ); - } - return true; - } - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @private - */ - function clear() { - var i; - for ( i = 0; i < pool.length; i++ ) { - pool[ i ].length = 0; - } - nbytes = 0; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6c12a4e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Typed array pool. -* -* @module @stdlib/array-pool -* -* @example -* var typedarraypool = require( '@stdlib/array-pool' ); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8f69ee3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,63 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @name typedarraypool -* @type {Function} -* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a valid array length or an array-like object -* @throws {TypeError} must provide a recognized data type -* @returns {(TypedArray|null)} typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -var typedarraypool = factory(); - - -// EXPORTS // - -module.exports = typedarraypool; diff --git a/lib/pool.js b/lib/pool.js deleted file mode 100644 index 5abd287..0000000 --- a/lib/pool.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Initializes a cache for pooled typed array buffers. -* -* @private -* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size -* @returns {ArrayArray} initialized cache -*/ -function pool( n ) { - var out; - var i; - - out = []; - for ( i = 0; i < n+1; i++ ) { - out.push( [] ); - } - return out; -} - - -// EXPORTS // - -module.exports = pool; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 95667c7..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'highWaterMark': 1024 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '01H2V,FD', options ) ); - } - if ( hasOwnProp( options, 'highWaterMark' ) ) { - opts.highWaterMark = options.highWaterMark; - if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( '01H2t,G9', 'highWaterMark', opts.highWaterMark ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 75bdae6..bd7b179 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Typed array pool.", "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,76 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessors": "^0.1.0", - "@stdlib/array-buffer": "^0.1.0", - "@stdlib/array-dtype": "^0.1.0", - "@stdlib/array-typed-ctors": "^0.1.0", - "@stdlib/assert-has-own-property": "^0.1.0", - "@stdlib/assert-is-arraybuffer": "^0.1.0", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-complex128array": "^0.1.0", - "@stdlib/assert-is-complex64array": "^0.1.0", - "@stdlib/assert-is-nonnegative-integer": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.0", - "@stdlib/assert-is-string": "^0.1.0", - "@stdlib/assert-is-typed-array-like": "^0.1.0", - "@stdlib/math-base-special-ceil": "^0.1.0", - "@stdlib/math-base-special-ceil2": "^0.1.0", - "@stdlib/math-base-special-floor": "^0.1.0", - "@stdlib/math-base-special-log2": "^0.1.0", - "@stdlib/math-base-special-min": "^0.1.0", - "@stdlib/strided-base-reinterpret-complex128": "^0.1.0", - "@stdlib/strided-base-reinterpret-complex64": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.1.0", - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-float32": "^0.1.0", - "@stdlib/array-float64": "^0.1.0", - "@stdlib/array-int16": "^0.1.0", - "@stdlib/array-int32": "^0.1.0", - "@stdlib/array-int8": "^0.1.0", - "@stdlib/array-uint16": "^0.1.0", - "@stdlib/array-uint32": "^0.1.0", - "@stdlib/array-uint8": "^0.1.0", - "@stdlib/array-uint8c": "^0.1.0", - "@stdlib/assert-instance-of": "^0.1.0", - "@stdlib/assert-is-complex-typed-array": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.0", - "@stdlib/assert-is-typed-array": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/complex-float32": "^0.1.0", - "@stdlib/complex-float64": "^0.1.0", - "@stdlib/complex-imag": "^0.1.0", - "@stdlib/complex-imagf": "^0.1.0", - "@stdlib/complex-real": "^0.1.0", - "@stdlib/complex-realf": "^0.1.0", - "@stdlib/math-base-special-pow": "^0.1.0", - "@stdlib/random-base-randu": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..31d7e9e --- /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 0566527..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,1797 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var typedarraypool = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 396aee2..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,2240 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function (no options)', function test( t ) { - t.strictEqual( typeof factory(), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - t.strictEqual( typeof factory( {} ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided a `highWaterMark` option which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (length)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a function which returns a typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, length)', function test( t ) { - var typedarraypool = factory(); - var arr; - - arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a `malloc` method which is a circular reference', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - var buf; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the returned function is a property which returns the pool\'s high water mark', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function supports specifying a high water mark which limits the total amount of memory a pool can allocate', function test( t ) { - var typedarraypool; - var arr1; - var arr2; - - typedarraypool = factory({ - 'highWaterMark': 64 // bytes - }); - - typedarraypool.clear(); - - arr1 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr1.length, 8, 'returns expected value' ); - t.strictEqual( arr1.byteLength, 64, 'returns expected value' ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - typedarraypool.free( arr1 ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Create an array which is less than or equal to the high water mark: - arr2 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr2.length, 8, 'returns expected value' ); - t.strictEqual( arr2.byteLength, 64, 'returns expected value' ); - - typedarraypool.free( arr2 ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a property which returns the total number of accumulated bytes', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var typedarraypool; - var arrs; - var i; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 54aa5ee..0000000 --- a/test/test.js +++ /dev/null @@ -1,1797 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var typedarraypool = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -}); From d4c0fc224beb3632d246622630cddb4ab645d748 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 5 Oct 2023 20:24:36 +0000 Subject: [PATCH 043/103] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index edfecbe..ae28056 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -34,7 +34,7 @@ var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); var accessors = require( '@stdlib/array-base-accessors' ); var adtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ArrayBuffer = require( '@stdlib/array-buffer' ); var ceil = require( '@stdlib/math-base-special-ceil' ); var floor = require( '@stdlib/math-base-special-floor' ); @@ -226,7 +226,7 @@ function factory( options ) { } ctor = ctors( dtype ); if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '01H2Y,KZ', dtype ) ); } if ( nargs <= 0 ) { return new ctor( 0 ); @@ -263,7 +263,7 @@ function factory( options ) { } return out; } - throw new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) ); + throw new TypeError( format( '01H2r,N0', arguments[ 0 ] ) ); } /** @@ -329,7 +329,7 @@ function factory( options ) { if ( isTypedArrayLike( buf ) && buf.buffer ) { buf = buf.buffer; } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) ); + throw new TypeError( format( '01H2s,N1', buf ) ); } if ( buf.byteLength > 0 ) { n = floor( log2( buf.byteLength ) ); diff --git a/lib/validate.js b/lib/validate.js index ce54890..95667c7 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '01H2V,FD', options ) ); } if ( hasOwnProp( options, 'highWaterMark' ) ) { opts.highWaterMark = options.highWaterMark; if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) ); + return new TypeError( format( '01H2t,G9', 'highWaterMark', opts.highWaterMark ) ); } } return null; diff --git a/package.json b/package.json index bb1c0f1..e21a43e 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "@stdlib/math-base-special-min": "^0.1.1", "@stdlib/strided-base-reinterpret-complex128": "^0.1.0", "@stdlib/strided-base-reinterpret-complex64": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From 3896ea7b031508f3c76e4fac825a025ec5fbe9ab Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 7 Oct 2023 03:59:25 +0000 Subject: [PATCH 044/103] Remove files --- index.d.ts | 359 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6541 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 c6a3785..0000000 --- a/index.d.ts +++ /dev/null @@ -1,359 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; -import ArrayBuffer = require( '@stdlib/array-buffer' ); - -/** -* Typed array or null. -*/ -type TypedArrayOrNull = RealOrComplexTypedArray | null; - -/** -* Interface defining pool options. -*/ -interface Options { - /** - * Maximum total memory which can be allocated. - */ - highWaterMark?: number; -} - -/** -* Pool interface. -*/ -interface Pool { - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr = typedarraypool(); - * // returns [] - * - * @example - * var arr = typedarraypool( 'float32' ); - * // returns [] - */ - ( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * // Allocate an array of doubles: - * var arr = typedarraypool( 5, 'float64' ); - * // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * typedarraypool.free( arr ); - * - * @example - * var arr1 = typedarraypool( [ 0.5, 0.5, 0.5 ] ); - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * @example - * var arr1 = [ 0.5, 0.5, 0.5 ]; - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - */ - ( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc(); - * // returns [] - * - * var arr2 = typedarraypool.calloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param length - typed array length - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc( 5 ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * var arr2 = typedarraypool.calloc( 5, 'uint8' ); - * // returns [ 0, 0, 0, 0, 0 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( length: number, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc(); - * // returns [] - * - * var arr2 = typedarraypool.malloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc( 5 ); - * // returns - * - * var arr2 = typedarraypool.malloc( 5, 'uint8' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 5.0, -3.0, 2.0 ] ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr2 = typedarraypool.malloc( arr1 ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr3 = typedarraypool.malloc( arr1, 'int32' ); - * // returns [ 5, -3, 2 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * typedarraypool.free( arr3 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ] ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * var arr2 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ], 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Frees a typed array or typed array buffer for use in a future allocation. - * - * @param buf - typed array or typed array buffer to free - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array for use in a future allocation: - * typedarraypool.free( arr ); - * - * // Create another typed array: - * arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array buffer for use in a future allocation: - * typedarraypool.free( arr.buffer ); - */ - free( buf: RealOrComplexTypedArray | ArrayBuffer ): void; - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr ); - * - * // ... - * - * // Clear all freed buffers: - * typedarraypool.clear(); - */ - clear(): void; - - /** - * Read-only property returning the pool's high water mark. - * - * ## Notes - * - * - Once a high water mark is reached, typed array allocation fails. - * - * @example - * var limit = typedarraypool.highWaterMark; - * // returns - */ - readonly highWaterMark: number; - - /** - * Read-only property returning the total number of allocated bytes. - * - * @example - * var arr = typedarraypool( 5, 'float64' ); - * - * var nbytes = typedarraypool.nbytes; - * // returns - */ - readonly nbytes: number; - - /** - * Creates a typed array pool. - * - * @param options - pool options - * @param options.highWaterMark - maximum total memory which can be allocated - * @throws must provide valid options - * @returns allocator - * - * @example - * var allocator = typedarraypool.factory(); - * - * // Allocate an array of doubles: - * var arr = allocator( 5, 'float64' ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * allocator.free( arr ); - */ - factory( options?: Options ): Pool; -} - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @param arg - an array length or an array-like object -* @param dtype - data type (default: 'float64') -* @returns typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -declare var typedarraypool: Pool; - - -// EXPORTS // - -export = typedarraypool; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9b88f36..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.0-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessors@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.1.0-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.1.0-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.1.0-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.1.0-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.1.0-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.0-esm/index.mjs";function k(e,t){return y(t)?w(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(c("01H2t,G9","highWaterMark",e.highWaterMark)):null:new TypeError(c("01H2V,FD",t))}function M(e){var t,r;for(t=[],r=0;rH.highWaterMark?null:(t=new j(e),w+=e,t)}function G(e,t,r){var s;return 0===t?new e(0):null===(s=F(u(t)*W[r]))?s:new e(s,0,t)}function K(){var e,i,n,l,j,v,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(n=d(i)))throw new TypeError(c("01H2Y,KZ",i));if(e<=0)return new n(0);if(r(arguments[0]))return G(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,m(l)?l=h(l,0):o(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=G(n,u,i)))return j;if(L(j)||T(j))return j.set(l),j;for(g=p(f(l)).accessors[0],v=p(i).accessors[1],b=0;b0){for(t=g(b(e.byteLength)),t=x(E.length-1,t),r=E[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '01H2Y,KZ', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = accessors( adtype( arr ) ).accessors[ 0 ];\n\t\t\tset = accessors( dtype ).accessors[ 1 ];\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '01H2r,N0', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( '01H2s,N1', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","accessors","adtype","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;ywEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,WAAY,gBAAiBP,EAAKI,gBAG3D,KARC,IAAIE,UAAWC,EAAQ,WAAYN,GAS5C,CC/BA,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,iHCaIG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EC/EO,CACNI,cAAiB,kBD+EbkB,UAAUC,SACdF,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOgB,EAAYC,EAAMC,EAAM1B,EAAKI,iBACpCgB,EAAS,EAETO,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB5B,EAAKI,eAC3C4B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOb,CACP,CASD,SAASc,EAAazB,GACrB,IAAI0B,EACAxB,EAMJ,OAHAA,EAAIe,EAAMjB,IAGDD,EAAKe,QAAUf,EAAMG,GAAIY,OAC1Bf,EAAMG,GAAIyB,MAGbhB,EAAOX,EAAIT,EAAKI,cACb,MAER+B,EAAM,IAAIE,EAAa5B,GAGvBW,GAAUX,EAEH0B,EACP,CAWD,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,EACzB,CAkBD,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAtB,EACAP,EACAmC,EACAC,EACAN,EACA7B,EAUJ,GALC8B,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAOzB,EAAO2B,IAEb,MAAM,IAAInC,UAAWC,EAAQ,WAAYkC,IAE1C,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKlC,EAAsBiB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAvB,EAAMK,UAAW,IACPC,OACL0B,EAAmBhC,GACvBA,EAAMiC,EAAgBjC,EAAK,GAChBkC,EAAkBlC,GAC7BA,EAAMmC,EAAenC,EAAK,GACf,WAAWoC,KAAMZ,KAE5BD,GAAO,GAGK,QADb9B,EAAM4B,EAAYC,EAAMC,EAAKC,IAE5B,OAAO/B,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAImC,IAAK5B,GACFP,EAKR,IAFAoC,EAAMQ,EAAWC,EAAQtC,IAAQqC,UAAW,GAC5CT,EAAMS,EAAWb,GAAQa,UAAW,GAC9B3C,EAAI,EAAGA,EAAI6B,EAAK7B,IACrBkC,EAAKnC,EAAKC,EAAGmC,EAAK7B,EAAKN,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,WAAYe,UAAW,IACpD,CAgBD,SAASO,IACR,IAAIe,EACAlC,EACA8C,EACA7C,EAUJ,GAAa,QANZD,EADc,KADfkC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCkC,EADItC,EAAiBR,GACfwC,EAAgBxC,EAAK,GAChBM,EAAgBN,GACrB0C,EAAe1C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAI6C,EAAIjC,OAAQZ,IAC5B6C,EAAK7C,GAAM,EAGb,OAAOD,CACP,CAcD,SAASoB,EAAMK,GACd,IAAI1B,EACAgD,EACA9C,EACJ,GAAK+C,EAAkBvB,IAASA,EAAIwB,OACnCxB,EAAMA,EAAIwB,YACJ,IAAMC,EAAezB,GAC3B,MAAM,IAAI7B,UAAWC,EAAQ,WAAY4B,IAE1C,GAAKA,EAAI0B,WAAa,EAAI,CAQzB,IAPApD,EAAIqD,EAAOpC,EAAMS,EAAI0B,aAGrBpD,EAAIsD,EAAKvD,EAAKe,OAAO,EAAGd,GAGxBgD,EAAIjD,EAAMC,GACJE,EAAI,EAAGA,EAAI8C,EAAElC,OAAQZ,IAC1B,GAAK8C,EAAG9C,KAAQwB,EACf,OAAO,EAITsB,EAAE7C,KAAMuB,EACR,CACD,OAAO,CACP,CAOD,SAASJ,IACR,IAAIpB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKe,OAAQZ,IAC7BH,EAAMG,GAAIY,OAAS,EAEpBH,EAAS,CACT,CACF,CEnTG,IAAC4C,EAAiB7C,ICPrBQ,EAAAsC,EAAA,UAAA9C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 31d7e9e..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 94fe54d0aa8f9f62bc9b151ddf0af6699804d390 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 7 Oct 2023 04:03:03 +0000 Subject: [PATCH 045/103] 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 | 43 +- benchmark/benchmark.calloc.js | 246 - benchmark/benchmark.factory.js | 71 - benchmark/benchmark.js | 246 - benchmark/benchmark.length.complex128.js | 102 - benchmark/benchmark.length.complex64.js | 102 - benchmark/benchmark.length.float32.js | 102 - benchmark/benchmark.length.float64.js | 102 - benchmark/benchmark.length.int16.js | 102 - benchmark/benchmark.length.int32.js | 102 - benchmark/benchmark.length.int8.js | 102 - benchmark/benchmark.length.uint16.js | 102 - benchmark/benchmark.length.uint32.js | 102 - benchmark/benchmark.length.uint8.js | 102 - benchmark/benchmark.length.uint8c.js | 102 - benchmark/benchmark.malloc.js | 246 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 347 -- docs/types/test.ts | 193 - examples/index.js | 80 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/bytes_per_element.json | 13 - lib/defaults.js | 42 - lib/factory.js | 370 -- lib/index.js | 56 - lib/main.js | 63 - lib/pool.js | 44 - lib/validate.js | 66 - package.json | 97 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 1797 ------ test/test.factory.js | 2240 -------- test/test.js | 1797 ------ 61 files changed, 6206 insertions(+), 12393 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.calloc.js delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.complex128.js delete mode 100644 benchmark/benchmark.length.complex64.js delete mode 100644 benchmark/benchmark.length.float32.js delete mode 100644 benchmark/benchmark.length.float64.js delete mode 100644 benchmark/benchmark.length.int16.js delete mode 100644 benchmark/benchmark.length.int32.js delete mode 100644 benchmark/benchmark.length.int8.js delete mode 100644 benchmark/benchmark.length.uint16.js delete mode 100644 benchmark/benchmark.length.uint32.js delete mode 100644 benchmark/benchmark.length.uint8.js delete mode 100644 benchmark/benchmark.length.uint8c.js delete mode 100644 benchmark/benchmark.malloc.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/bytes_per_element.json delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/pool.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ea35f20..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/array/pool) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6f7c875..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/array/pool) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 4f5a65c..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -493,7 +492,7 @@ console.log( 'nbytes: %d', typedarray.nbytes ); ## 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]. @@ -559,7 +558,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm diff --git a/benchmark/benchmark.calloc.js b/benchmark/benchmark.calloc.js deleted file mode 100644 index e5a1c77..0000000 --- a/benchmark/benchmark.calloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':calloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index f7cd676..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = typedarray.factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:highWaterMark', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'highWaterMark': 0 - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.highWaterMark = i; - f = typedarray.factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a023d2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.complex128.js b/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 47b623b..0000000 --- a/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex64.js b/benchmark/benchmark.length.complex64.js deleted file mode 100644 index 40a412b..0000000 --- a/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float32.js b/benchmark/benchmark.length.float32.js deleted file mode 100644 index 0227ed7..0000000 --- a/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float64.js b/benchmark/benchmark.length.float64.js deleted file mode 100644 index 2dbac1c..0000000 --- a/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int16.js b/benchmark/benchmark.length.int16.js deleted file mode 100644 index e2a8adc..0000000 --- a/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int32.js b/benchmark/benchmark.length.int32.js deleted file mode 100644 index e4df0aa..0000000 --- a/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int8.js b/benchmark/benchmark.length.int8.js deleted file mode 100644 index 7ceac11..0000000 --- a/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint16.js b/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 9a532b6..0000000 --- a/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint32.js b/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 98f2d7f..0000000 --- a/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8.js b/benchmark/benchmark.length.uint8.js deleted file mode 100644 index 8359249..0000000 --- a/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8c.js b/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index d47d023..0000000 --- a/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.malloc.js b/benchmark/benchmark.malloc.js deleted file mode 100644 index d4eea72..0000000 --- a/benchmark/benchmark.malloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':malloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 9689761..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/array/pool" -%% click B href "https://github.com/stdlib-js/array-pool/tree/main" -%% click C href "https://github.com/stdlib-js/array-pool/tree/production" -%% click D href "https://github.com/stdlib-js/array-pool/tree/esm" -%% click E href "https://github.com/stdlib-js/array-pool/tree/deno" -%% click F href "https://github.com/stdlib-js/array-pool/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/pool -[production-url]: https://github.com/stdlib-js/array-pool/tree/production -[deno-url]: https://github.com/stdlib-js/array-pool/tree/deno -[umd-url]: https://github.com/stdlib-js/array-pool/tree/umd -[esm-url]: https://github.com/stdlib-js/array-pool/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 5160b6f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import typedarraypool from '../docs/types/index'; -export = typedarraypool; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 9d31d69..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var l=function(n,i){return function(){return i||n((i={exports:{}}).exports,i),i.exports}};var k=l(function(kr,M){ -function D(){return{highWaterMark:9007199254740992}}M.exports=D -});var E=l(function(Ar,W){ -var G=require('@stdlib/assert-is-plain-object/dist'),H=require('@stdlib/assert-has-own-property/dist'),J=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,A=require('@stdlib/error-tools-fmtprodmsg/dist');function K(n,i){return G(i)?H(i,"highWaterMark")&&(n.highWaterMark=i.highWaterMark,!J(n.highWaterMark))?new TypeError(A('01H2t',"highWaterMark",n.highWaterMark)):null:new TypeError(A('01H2V',i));}W.exports=K -});var C=l(function(Wr,T){ -function Q(n){var i,u;for(i=[],u=0;uv.highWaterMark?null:(e=new ur(r),i+=r,e)}function d(r,e,t){var a;return e===0?new r(0):(a=_(lr(e)*hr[t]),a===null?a:new r(a,0,e))}function s(){var r,e,t,a,o,x,w,c,f;if(r=arguments.length,r&&X(arguments[r-1])?(r-=1,e=arguments[r]):e="float64",t=y(e),t===null)throw new TypeError(m('01H2Y',e));if(r<=0)return new t(0);if(Z(arguments[0]))return d(t,arguments[0],e);if($(arguments[0])){if(a=arguments[0],c=a.length,tr(a)?a=P(a,0):ar(a)?a=b(a,0):/^complex/.test(e)&&(c/=2),o=d(t,c,e),o===null)return o;if(L(o)||N(o))return o.set(a),o;for(w=B(nr(a)).accessors[0],x=B(e).accessors[1],f=0;f0){for(e=or(p(r.byteLength)),e=vr(u.length-1,e),t=u[e],a=0;a[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = accessors( adtype( arr ) ).accessors[ 0 ];\n\t\t\tset = accessors( dtype ).accessors[ 1 ];\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nmodule.exports = typedarraypool;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* var typedarraypool = require( '@stdlib/array-pool' );\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,cAAiB,gBAClB,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,eAAgB,IACzCD,EAAK,cAAgBC,EAAQ,cACxB,CAACJ,EAAsBG,EAAK,aAAc,GACvC,IAAI,UAAWF,EAAQ,2EAA4E,gBAAiBE,EAAK,aAAc,CAAE,EAG3I,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cA6BA,SAASC,EAAM,EAAI,CAClB,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAI,EAAE,EAAGA,IACrBD,EAAI,KAAM,CAAC,CAAE,EAEd,OAAOA,CACR,CAKAF,EAAO,QAAUC,IC3CjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,QAAW,EACX,QAAW,EACX,MAAS,EACT,MAAS,EACT,KAAQ,EACR,OAAU,EACV,OAAU,EACV,MAAS,EACT,OAAU,EACT,UAAa,EACb,WAAc,EAChB,ICZA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAe,QAAS,8BAA+B,EACvDC,GAAmB,QAAS,oCAAqC,EACjEC,GAAgB,QAAS,+BAAgC,EACzDC,GAAmB,QAAS,kCAAmC,EAC/DC,GAAoB,QAAS,mCAAoC,EACjEC,EAAc,QAAS,uDAAwD,EAC/EC,GAAsB,QAAS,uDAAwD,EACvFC,EAAQ,QAAS,2BAA4B,EAC7CC,EAAgB,QAAS,4CAA6C,EACtEC,EAAiB,QAAS,6CAA8C,EACxEC,EAAY,QAAS,8BAA+B,EACpDC,GAAS,QAAS,qBAAsB,EACxCC,EAAS,QAAS,uBAAwB,EAC1CC,GAAc,QAAS,sBAAuB,EAC9CC,GAAO,QAAS,gCAAiC,EACjDC,GAAQ,QAAS,iCAAkC,EACnDC,GAAQ,QAAS,iCAAkC,EACnDC,EAAO,QAAS,gCAAiC,EACjDC,GAAM,QAAS,+BAAgC,EAC/CC,GAAW,IACXC,GAAW,IACXC,GAAa,IACbC,GAAoB,IAKpBC,GAAiBhB,EAAO,WAAY,EACpCiB,GAAkBjB,EAAO,YAAa,EAY1C,SAASkB,EAAgBC,EAAM,CAC9B,OAASA,aAAeH,EACzB,CASA,SAASI,EAAiBD,EAAM,CAC/B,OAASA,aAAeF,EACzB,CA6BA,SAASI,GAASC,EAAU,CAC3B,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,EAAOb,GAAS,EACX,UAAU,SACdc,EAAMb,GAAUY,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAAF,EAAOV,GAAYP,GAAMG,EAAMe,EAAK,aAAc,CAAE,CAAE,EACtDF,EAAS,EAETzB,EAAa6B,EAAQ,SAAUA,CAAO,EACtC7B,EAAa6B,EAAQ,SAAUC,CAAO,EACtC9B,EAAa6B,EAAQ,OAAQE,CAAK,EAClC/B,EAAa6B,EAAQ,QAASG,CAAM,EACpChC,EAAa6B,EAAQ,gBAAiBF,EAAK,aAAc,EACzD1B,GAAqB4B,EAAQ,SAAUI,CAAS,EAEzCJ,EAQP,SAASI,GAAW,CACnB,OAAOR,CACR,CASA,SAASS,EAAaC,EAAI,CACzB,IAAIC,EACAC,EAMJ,OAHAA,EAAIzB,EAAMuB,CAAE,EAGPE,EAAIX,EAAK,QAAUA,EAAMW,CAAE,EAAE,OAC1BX,EAAMW,CAAE,EAAE,IAAI,EAGjBZ,EAAOU,EAAIR,EAAK,cACb,MAERS,EAAM,IAAI5B,GAAa2B,CAAE,EAGzBV,GAAUU,EAEHC,EACR,CAWA,SAASE,EAAYC,EAAMC,EAAKC,EAAQ,CACvC,IAAIL,EACJ,OAAKI,IAAQ,EACL,IAAID,EAAM,CAAE,GAEpBH,EAAMF,EAAavB,GAAO6B,CAAI,EAAEvB,GAAmBwB,CAAM,CAAE,EACtDL,IAAQ,KACLA,EAED,IAAIG,EAAMH,EAAK,EAAGI,CAAI,EAC9B,CAkBA,SAASX,GAAS,CACjB,IAAIa,EACAD,EACAF,EACAlB,EACAsB,EACAC,EACAC,EACAL,EACAH,EAUJ,GARAK,EAAQ,UAAU,OACbA,GAASjD,EAAU,UAAWiD,EAAM,CAAE,CAAE,GAC5CA,GAAS,EACTD,EAAQ,UAAWC,CAAM,GAEzBD,EAAQ,UAETF,EAAOrC,EAAOuC,CAAM,EACfF,IAAS,KACb,MAAM,IAAI,UAAWhC,EAAQ,sEAAuEkC,CAAM,CAAE,EAE7G,GAAKC,GAAS,EACb,OAAO,IAAIH,EAAM,CAAE,EAGpB,GAAK7C,EAAsB,UAAW,CAAE,CAAE,EACzC,OAAO4C,EAAYC,EAAM,UAAW,CAAE,EAAGE,CAAM,EAGhD,GAAK9C,EAAc,UAAW,CAAE,CAAE,EAAI,CAYrC,GAXA0B,EAAM,UAAW,CAAE,EACnBmB,EAAMnB,EAAI,OACLtB,GAAmBsB,CAAI,EAC3BA,EAAMjB,EAAgBiB,EAAK,CAAE,EAClBvB,GAAkBuB,CAAI,EACjCA,EAAMlB,EAAekB,EAAK,CAAE,EACjB,WAAW,KAAMoB,CAAM,IAElCD,GAAO,GAERG,EAAML,EAAYC,EAAMC,EAAKC,CAAM,EAC9BE,IAAQ,KACZ,OAAOA,EAER,GAAKrB,EAAiBqB,CAAI,GAAKvB,EAAgBuB,CAAI,EAClD,OAAAA,EAAI,IAAKtB,CAAI,EACNsB,EAKR,IAFAE,EAAMxC,EAAWC,GAAQe,CAAI,CAAE,EAAE,UAAW,CAAE,EAC9CuB,EAAMvC,EAAWoC,CAAM,EAAE,UAAW,CAAE,EAChCJ,EAAI,EAAGA,EAAIG,EAAKH,IACrBO,EAAKD,EAAKN,EAAGQ,EAAKxB,EAAKgB,CAAE,CAAE,EAE5B,OAAOM,CACR,CACA,MAAM,IAAI,UAAWpC,EAAQ,wGAAyG,UAAW,CAAE,CAAE,CAAE,CACxJ,CAgBA,SAASuB,GAAS,CACjB,IAAIY,EACAC,EACAG,EACAT,EAUJ,GARAK,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAMd,EAAO,EACFa,IAAU,EACrBC,EAAMd,EAAQ,UAAW,CAAE,CAAE,EAE7Bc,EAAMd,EAAQ,UAAW,CAAE,EAAG,UAAW,CAAE,CAAE,EAEzCc,IAAQ,KASZ,IAPKrB,EAAiBqB,CAAI,EACzBG,EAAM1C,EAAgBuC,EAAK,CAAE,EAClBvB,EAAgBuB,CAAI,EAC/BG,EAAM3C,EAAewC,EAAK,CAAE,EAE5BG,EAAMH,EAEDN,EAAI,EAAGA,EAAIS,EAAI,OAAQT,IAC5BS,EAAKT,CAAE,EAAI,EAGb,OAAOM,CACR,CAcA,SAASZ,EAAMK,EAAM,CACpB,IAAID,EACAY,EACAV,EACJ,GAAKzC,GAAkBwC,CAAI,GAAKA,EAAI,OACnCA,EAAMA,EAAI,eACC,CAACvC,GAAeuC,CAAI,EAC/B,MAAM,IAAI,UAAW7B,EAAQ,4EAA6E6B,CAAI,CAAE,EAEjH,GAAKA,EAAI,WAAa,EAAI,CAQzB,IAPAD,EAAIzB,GAAOE,EAAMwB,EAAI,UAAW,CAAE,EAGlCD,EAAItB,GAAKa,EAAK,OAAO,EAAGS,CAAE,EAG1BY,EAAIrB,EAAMS,CAAE,EACNE,EAAI,EAAGA,EAAIU,EAAE,OAAQV,IAC1B,GAAKU,EAAGV,CAAE,IAAMD,EACf,MAAO,GAITW,EAAE,KAAMX,CAAI,CACb,CACA,MAAO,EACR,CAOA,SAASJ,GAAQ,CAChB,IAAIK,EACJ,IAAMA,EAAI,EAAGA,EAAIX,EAAK,OAAQW,IAC7BX,EAAMW,CAAE,EAAE,OAAS,EAEpBZ,EAAS,CACV,CACD,CAKAjC,EAAO,QAAU+B,KCjXjB,IAAAyB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAU,IAmCVC,GAAiBD,GAAQ,EAK7BD,EAAO,QAAUE,KCnBjB,IAAIC,GAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,GAAU,IAKdF,GAAaC,EAAM,UAAWC,EAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isNonNegativeInteger", "format", "validate", "opts", "options", "require_pool", "__commonJSMin", "exports", "module", "pool", "out", "i", "require_bytes_per_element", "__commonJSMin", "exports", "module", "require_factory", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isCollection", "isTypedArrayLike", "isArrayBuffer", "isComplex64Array", "isComplex128Array", "setReadOnly", "setReadOnlyAccessor", "ctors", "reinterpret64", "reinterpret128", "accessors", "adtype", "format", "ArrayBuffer", "ceil", "floor", "ceil2", "log2", "min", "defaults", "validate", "createPool", "BYTES_PER_ELEMENT", "Complex64Array", "Complex128Array", "isCmplx64Array", "arr", "isCmplx128Array", "factory", "options", "nbytes", "pool", "opts", "err", "malloc", "calloc", "free", "clear", "getBytes", "arraybuffer", "n", "buf", "i", "typedarray", "ctor", "len", "dtype", "nargs", "out", "set", "get", "tmp", "p", "require_main", "__commonJSMin", "exports", "module", "factory", "typedarraypool", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5244595..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,347 +0,0 @@ - -{{alias}}( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - Memory is **uninitialized**, which means that the contents of a returned - typed array may contain sensitive contents. - - The function supports the following data types: - - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - The default typed array data type is `float64`. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}() - [] - > arr = {{alias}}( 'float32' ) - [] - - -{{alias}}( length[, dtype] ) - Returns an uninitialized typed array having a specified length from a typed - array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > arr = {{alias}}( 5, 'int32' ) - - - -{{alias}}( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - This method shares the same security vulnerabilities mentioned above. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc() - - > arr = {{alias}}.malloc( 'float32' ) - - - -{{alias}}.malloc( length[, dtype] ) - Returns a typed array having a specified length from a typed array memory - pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc( 5 ) - - > arr = {{alias}}.malloc( 5, 'int32' ) - - - -{{alias}}.malloc( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}.malloc( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.calloc( [dtype] ) - Returns a zero-initialized typed array from a typed array memory pool. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc() - [] - > arr = {{alias}}.calloc( 'float32' ) - [] - - -{{alias}}.calloc( length[, dtype] ) - Returns a zero-initialized typed array having a specified length from a - typed array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}.calloc( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}.free( buf ) - Frees a typed array or typed array buffer for use in a future allocation. - - Parameters - ---------- - buf: TypedArray|ArrayBuffer - Typed array or typed array buffer to free. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ) - - -{{alias}}.clear() - Clears the typed array pool allowing garbage collection of previously - allocated (and currently free) array buffers. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - > {{alias}}.clear() - - -{{alias}}.highWaterMark - Read-only property returning the pool's high water mark. - - Once a high water mark is reached, typed array allocation fails. - - Examples - -------- - > {{alias}}.highWaterMark - - -{{alias}}.nbytes - Read-only property returning the total number of allocated bytes. - - The returned value is the total accumulated value. Hence, anytime a pool - must allocate a new array buffer (i.e., more memory), the pool increments - this value. - - The only time this value is decremented is when a pool is cleared. - - This behavior means that, while allocated buffers which are never freed may, - in fact, be garbage collected, they continue to count against the high water - mark limit. - - Accordingly, you should *always* free allocated buffers in order to prevent - the pool from believing that non-freed buffers are continually in use. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.nbytes - - -{{alias}}.factory( [options] ) - Creates a typed array pool. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.highWaterMark: integer (optional) - Maximum total memory (in bytes) which can be allocated. - - Returns - ------- - fcn: Function - Function for creating typed arrays from a typed array memory pool. - - Examples - -------- - > var pool = {{alias}}.factory(); - > var arr1 = pool( 3, 'float64' ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1014bba..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,193 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-empty */ -/* tslint:disable:no-unused-expression */ - -import typedarraypool = require( './index' ); - - -// TESTS // - -// The function returns a typed array or null... -{ - typedarraypool(); // $ExpectType TypedArrayOrNull - typedarraypool( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the function is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool( true ); // $ExpectError - typedarraypool( false ); // $ExpectError - typedarraypool( null ); // $ExpectError - typedarraypool( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized data type... -{ - typedarraypool( 4, true ); // $ExpectError - typedarraypool( 4, false ); // $ExpectError - typedarraypool( 4, null ); // $ExpectError - typedarraypool( 4, 'abc' ); // $ExpectError - typedarraypool( 4, 123 ); // $ExpectError - typedarraypool( 4, [] ); // $ExpectError - typedarraypool( 4, {} ); // $ExpectError - typedarraypool( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an incorrect number of arguments... -{ - typedarraypool( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `malloc` method which returns a typed array or null... -{ - typedarraypool.malloc(); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.malloc( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `malloc` method is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool.malloc( true ); // $ExpectError - typedarraypool.malloc( false ); // $ExpectError - typedarraypool.malloc( null ); // $ExpectError - typedarraypool.malloc( {} ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.malloc( 4, true ); // $ExpectError - typedarraypool.malloc( 4, false ); // $ExpectError - typedarraypool.malloc( 4, null ); // $ExpectError - typedarraypool.malloc( 4, 'abc' ); // $ExpectError - typedarraypool.malloc( 4, 123 ); // $ExpectError - typedarraypool.malloc( 4, [] ); // $ExpectError - typedarraypool.malloc( 4, {} ); // $ExpectError - typedarraypool.malloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided an incorrect number of arguments... -{ - typedarraypool.malloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `calloc` method which returns a typed array or null... -{ - typedarraypool.calloc(); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `calloc` method is provided a first argument which is not a number... -{ - typedarraypool.calloc( 'abc' ); // $ExpectError - typedarraypool.calloc( true ); // $ExpectError - typedarraypool.calloc( false ); // $ExpectError - typedarraypool.calloc( null ); // $ExpectError - typedarraypool.calloc( {} ); // $ExpectError - typedarraypool.calloc( [] ); // $ExpectError - typedarraypool.calloc( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.calloc( 4, true ); // $ExpectError - typedarraypool.calloc( 4, false ); // $ExpectError - typedarraypool.calloc( 4, null ); // $ExpectError - typedarraypool.calloc( 4, 'abc' ); // $ExpectError - typedarraypool.calloc( 4, 123 ); // $ExpectError - typedarraypool.calloc( 4, [] ); // $ExpectError - typedarraypool.calloc( 4, {} ); // $ExpectError - typedarraypool.calloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided an incorrect number of arguments... -{ - typedarraypool.calloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `factory` method which returns a typed array pool.. -{ - typedarraypool.factory(); // $ExpectType Pool - typedarraypool.factory( { 'highWaterMark': 556 } ); // $ExpectType Pool -} - -// The compiler throws an error if the `factory` method is provided a `highWaterMark` option which is not a number... -{ - typedarraypool.factory( { 'highWaterMark': true } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': false } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': 'abc' } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': null } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': [] } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': {} } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an incorrect number of arguments... -{ - typedarraypool.factory( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` method which returns void... -{ - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.free( arr ); // $ExpectType void -} - -// The compiler throws an error if the `free` method is provided a first argument which is neither a typed array nor array buffer... -{ - typedarraypool.free( true ); // $ExpectError - typedarraypool.free( false ); // $ExpectError - typedarraypool.free( 123 ); // $ExpectError - typedarraypool.free( 'abc' ); // $ExpectError - typedarraypool.free( null ); // $ExpectError - typedarraypool.free( {} ); // $ExpectError - typedarraypool.free( ( x: number ): number => x ); // $ExpectError -} - -// Attached to the main export is a `clear` method which returns void... -{ - typedarraypool.clear(); // $ExpectType void -} - -// The compiler throws an error if the `clear` method is provided arguments... -{ - typedarraypool.clear( {} ); // $ExpectError - typedarraypool.clear( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `highWaterMark` property... -{ - typedarraypool.highWaterMark; // $ExpectType number -} - -// Attached to the main export is a `nbytes` property... -{ - typedarraypool.nbytes; // $ExpectType number -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 24a7846..0000000 --- a/examples/index.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 randu = require( '@stdlib/random-base-randu' ); -var typedarraypool = require( './../lib' ); - -// Create a typed array pool which can allocate at most 1GB: -var typedarray = typedarraypool.factory({ - 'highWaterMark': 1e9 -}); - -// Inspect the pool: -console.log( 'Max bytes: %d', typedarray.highWaterMark ); -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Allocate an array for storing double-precision floating-point numbers: -var arr1 = typedarray( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Fill the array... -var i; -for ( i = 0; i < arr1.length; i++ ) { - arr1[ i ] = randu(); -} - -// Inspect array contents: -console.log( arr1 ); - -// Free the array: -typedarray.free( arr1 ); - -// Allocate another array similar to the previous one: -var arr2 = typedarray( 5, 'float64' ); -// returns - -// Check that we have been returned a new typed array view: -console.log( arr2 === arr1 ); -// => false - -// Inspect array contents: -console.log( arr2 ); - -// Free the array: -typedarray.free( arr2 ); - -// Allocate an initialized array: -var arr3 = typedarray.calloc( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect array contents: -console.log( arr3 ); - -// Free the array: -typedarray.free( arr3 ); - -// Clear the pool: -typedarray.clear(); - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index de70cb0..c6a3785 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; import ArrayBuffer = require( '@stdlib/array-buffer' ); diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c29a166 --- /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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessors@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.1.0-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.1.0-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.1.0-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.1.0-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.1.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";function k(e,t){return y(t)?w(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(c("01H2t,G9","highWaterMark",e.highWaterMark)):null:new TypeError(c("01H2V,FD",t))}function M(e){var t,r;for(t=[],r=0;rH.highWaterMark?null:(t=new j(e),w+=e,t)}function G(e,t,r){var s;return 0===t?new e(0):null===(s=F(u(t)*W[r]))?s:new e(s,0,t)}function K(){var e,i,n,l,j,v,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(n=d(i)))throw new TypeError(c("01H2Y,KZ",i));if(e<=0)return new n(0);if(r(arguments[0]))return G(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,m(l)?l=h(l,0):o(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=G(n,u,i)))return j;if(L(j)||T(j))return j.set(l),j;for(g=p(f(l)).accessors[0],v=p(i).accessors[1],b=0;b0){for(t=g(b(e.byteLength)),t=x(E.length-1,t),r=E[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '01H2Y,KZ', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = accessors( adtype( arr ) ).accessors[ 0 ];\n\t\t\tset = accessors( dtype ).accessors[ 1 ];\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '01H2r,N0', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( '01H2s,N1', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","accessors","adtype","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;ywEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,WAAY,gBAAiBP,EAAKI,gBAG3D,KARC,IAAIE,UAAWC,EAAQ,WAAYN,GAS5C,CC/BA,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,iHCaIG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EC/EO,CACNI,cAAiB,kBD+EbkB,UAAUC,SACdF,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOgB,EAAYC,EAAMC,EAAM1B,EAAKI,iBACpCgB,EAAS,EAETO,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB5B,EAAKI,eAC3C4B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOb,CACP,CASD,SAASc,EAAazB,GACrB,IAAI0B,EACAxB,EAMJ,OAHAA,EAAIe,EAAMjB,IAGDD,EAAKe,QAAUf,EAAMG,GAAIY,OAC1Bf,EAAMG,GAAIyB,MAGbhB,EAAOX,EAAIT,EAAKI,cACb,MAER+B,EAAM,IAAIE,EAAa5B,GAGvBW,GAAUX,EAEH0B,EACP,CAWD,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,EACzB,CAkBD,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAtB,EACAP,EACAmC,EACAC,EACAN,EACA7B,EAUJ,GALC8B,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAOzB,EAAO2B,IAEb,MAAM,IAAInC,UAAWC,EAAQ,WAAYkC,IAE1C,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKlC,EAAsBiB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAvB,EAAMK,UAAW,IACPC,OACL0B,EAAmBhC,GACvBA,EAAMiC,EAAgBjC,EAAK,GAChBkC,EAAkBlC,GAC7BA,EAAMmC,EAAenC,EAAK,GACf,WAAWoC,KAAMZ,KAE5BD,GAAO,GAGK,QADb9B,EAAM4B,EAAYC,EAAMC,EAAKC,IAE5B,OAAO/B,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAImC,IAAK5B,GACFP,EAKR,IAFAoC,EAAMQ,EAAWC,EAAQtC,IAAQqC,UAAW,GAC5CT,EAAMS,EAAWb,GAAQa,UAAW,GAC9B3C,EAAI,EAAGA,EAAI6B,EAAK7B,IACrBkC,EAAKnC,EAAKC,EAAGmC,EAAK7B,EAAKN,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,WAAYe,UAAW,IACpD,CAgBD,SAASO,IACR,IAAIe,EACAlC,EACA8C,EACA7C,EAUJ,GAAa,QANZD,EADc,KADfkC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCkC,EADItC,EAAiBR,GACfwC,EAAgBxC,EAAK,GAChBM,EAAgBN,GACrB0C,EAAe1C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAI6C,EAAIjC,OAAQZ,IAC5B6C,EAAK7C,GAAM,EAGb,OAAOD,CACP,CAcD,SAASoB,EAAMK,GACd,IAAI1B,EACAgD,EACA9C,EACJ,GAAK+C,EAAkBvB,IAASA,EAAIwB,OACnCxB,EAAMA,EAAIwB,YACJ,IAAMC,EAAezB,GAC3B,MAAM,IAAI7B,UAAWC,EAAQ,WAAY4B,IAE1C,GAAKA,EAAI0B,WAAa,EAAI,CAQzB,IAPApD,EAAIqD,EAAOpC,EAAMS,EAAI0B,aAGrBpD,EAAIsD,EAAKvD,EAAKe,OAAO,EAAGd,GAGxBgD,EAAIjD,EAAMC,GACJE,EAAI,EAAGA,EAAI8C,EAAElC,OAAQZ,IAC1B,GAAK8C,EAAG9C,KAAQwB,EACf,OAAO,EAITsB,EAAE7C,KAAMuB,EACR,CACD,OAAO,CACP,CAOD,SAASJ,IACR,IAAIpB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKe,OAAQZ,IAC7BH,EAAMG,GAAIY,OAAS,EAEpBH,EAAS,CACT,CACF,CEnTG,IAAC4C,EAAiB7C,ICPrBQ,EAAAsC,EAAA,UAAA9C"} \ No newline at end of file diff --git a/lib/bytes_per_element.json b/lib/bytes_per_element.json deleted file mode 100644 index f97fe70..0000000 --- a/lib/bytes_per_element.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "float64": 8, - "float32": 4, - "int16": 2, - "int32": 4, - "int8": 1, - "uint16": 2, - "uint32": 4, - "uint8": 1, - "uint8c": 1, - "complex64": 8, - "complex128": 16 -} diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index a421711..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +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'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'highWaterMark': 9007199254740992 - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index ae28056..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,370 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var isComplex64Array = require( '@stdlib/assert-is-complex64array' ); -var isComplex128Array = require( '@stdlib/assert-is-complex128array' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var ctors = require( '@stdlib/array-typed-ctors' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var accessors = require( '@stdlib/array-base-accessors' ); -var adtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil = require( '@stdlib/math-base-special-ceil' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); -var log2 = require( '@stdlib/math-base-special-log2' ); -var min = require( '@stdlib/math-base-special-min' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var createPool = require( './pool.js' ); -var BYTES_PER_ELEMENT = require( './bytes_per_element.json' ); - - -// VARIABLES // - -var Complex64Array = ctors( 'complex64' ); -var Complex128Array = ctors( 'complex128' ); - - -// FUNCTIONS // - -/** -* Tests whether an array is a single-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a single-precision complex floating-point number array -*/ -function isCmplx64Array( arr ) { - return ( arr instanceof Complex64Array ); -} - -/** -* Tests whether an array is a double-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a double-precision complex floating-point number array -*/ -function isCmplx128Array( arr ) { - return ( arr instanceof Complex128Array ); -} - - -// MAIN // - -/** -* Creates a typed array pool. -* -* @param {Options} [options] - pool options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} allocator -* -* @example -* var typedarraypool = factory(); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -function factory( options ) { - var nbytes; - var pool; - var opts; - var err; - - opts = defaults(); - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - pool = createPool( ceil( log2( opts.highWaterMark ) ) ); - nbytes = 0; - - setReadOnly( malloc, 'malloc', malloc ); // circular reference - setReadOnly( malloc, 'calloc', calloc ); - setReadOnly( malloc, 'free', free ); - setReadOnly( malloc, 'clear', clear ); - setReadOnly( malloc, 'highWaterMark', opts.highWaterMark ); - setReadOnlyAccessor( malloc, 'nbytes', getBytes ); - - return malloc; - - /** - * Returns the number of allocated bytes. - * - * @private - * @returns {NonNegativeInteger} number of allocated bytes - */ - function getBytes() { - return nbytes; - } - - /** - * Returns an array buffer. - * - * @private - * @param {NonNegativeInteger} n - number of bytes - * @returns {(ArrayBuffer|null)} array buffer or null - */ - function arraybuffer( n ) { - var buf; - var i; - - // Convert the number of bytes to an index in our pool table: - i = log2( n ); - - // If we already have an available array buffer, use it... - if ( i < pool.length && pool[ i ].length ) { - return pool[ i ].pop(); - } - // Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate... - if ( nbytes+n > opts.highWaterMark ) { - return null; - } - buf = new ArrayBuffer( n ); - - // Update the running counter of allocated bytes: - nbytes += n; - - return buf; - } - - /** - * Returns a typed array. - * - * @private - * @param {Function} ctor - typed array constructor - * @param {NonNegativeInteger} len - view length - * @param {string} dtype - data type - * @returns {(TypedArray|null)} typed array or null - */ - function typedarray( ctor, len, dtype ) { - var buf; - if ( len === 0 ) { - return new ctor( 0 ); - } - buf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] ); - if ( buf === null ) { - return buf; - } - return new ctor( buf, 0, len ); - } - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length or an array-like object - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function malloc() { - var nargs; - var dtype; - var ctor; - var arr; - var out; - var set; - var get; - var len; - var i; - - nargs = arguments.length; - if ( nargs && isString( arguments[ nargs-1 ] ) ) { - nargs -= 1; - dtype = arguments[ nargs ]; - } else { - dtype = 'float64'; - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( '01H2Y,KZ', dtype ) ); - } - if ( nargs <= 0 ) { - return new ctor( 0 ); - } - // Check if provided a typed array length... - if ( isNonNegativeInteger( arguments[ 0 ] ) ) { - return typedarray( ctor, arguments[ 0 ], dtype ); - } - // Check if provided an array-like object containing data elements... - if ( isCollection( arguments[ 0 ] ) ) { - arr = arguments[ 0 ]; - len = arr.length; - if ( isComplex128Array( arr ) ) { - arr = reinterpret128( arr, 0 ); - } else if ( isComplex64Array( arr ) ) { - arr = reinterpret64( arr, 0 ); - } else if ( /^complex/.test( dtype ) ) { - // Assume we've been provided an array of interleaved real and imaginary components... - len /= 2; - } - out = typedarray( ctor, len, dtype ); - if ( out === null ) { - return out; - } - if ( isCmplx128Array( out ) || isCmplx64Array( out ) ) { - out.set( arr ); - return out; - } - // Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other "unsafe" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things... - get = accessors( adtype( arr ) ).accessors[ 0 ]; - set = accessors( dtype ).accessors[ 1 ]; - for ( i = 0; i < len; i++ ) { - set( out, i, get( arr, i ) ); - } - return out; - } - throw new TypeError( format( '01H2r,N0', arguments[ 0 ] ) ); - } - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {NonNegativeInteger} [len=0] - array length - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function calloc() { - var nargs; - var out; - var tmp; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - out = malloc(); - } else if ( nargs === 1 ) { - out = malloc( arguments[ 0 ] ); - } else { - out = malloc( arguments[ 0 ], arguments[ 1 ] ); - } - if ( out !== null ) { - // Initialize the memory... - if ( isCmplx128Array( out ) ) { - tmp = reinterpret128( out, 0 ); - } else if ( isCmplx64Array( out ) ) { - tmp = reinterpret64( out, 0 ); - } else { - tmp = out; - } - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = 0.0; - } - } - return out; - } - - /** - * Frees a typed array or typed array buffer. - * - * ## Notes - * - * - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., "freeing" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool. - * - * @private - * @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free - * @throws {TypeError} must provide a typed array or typed array buffer - * @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed - */ - function free( buf ) { - var n; - var p; - var i; - if ( isTypedArrayLike( buf ) && buf.buffer ) { - buf = buf.buffer; - } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( '01H2s,N1', buf ) ); - } - if ( buf.byteLength > 0 ) { - n = floor( log2( buf.byteLength ) ); - - // Prohibit "freeing" array buffers which would potentially allow users to circumvent high water mark limits: - n = min( pool.length-1, n ); - - // Ensure that we do not attempt to free the same buffer more than once... - p = pool[ n ]; - for ( i = 0; i < p.length; i++ ) { - if ( p[ i ] === buf ) { - return false; - } - } - // Add the buffer to our pool of free buffers: - p.push( buf ); - } - return true; - } - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @private - */ - function clear() { - var i; - for ( i = 0; i < pool.length; i++ ) { - pool[ i ].length = 0; - } - nbytes = 0; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6c12a4e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Typed array pool. -* -* @module @stdlib/array-pool -* -* @example -* var typedarraypool = require( '@stdlib/array-pool' ); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8f69ee3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,63 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @name typedarraypool -* @type {Function} -* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a valid array length or an array-like object -* @throws {TypeError} must provide a recognized data type -* @returns {(TypedArray|null)} typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -var typedarraypool = factory(); - - -// EXPORTS // - -module.exports = typedarraypool; diff --git a/lib/pool.js b/lib/pool.js deleted file mode 100644 index 5abd287..0000000 --- a/lib/pool.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Initializes a cache for pooled typed array buffers. -* -* @private -* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size -* @returns {ArrayArray} initialized cache -*/ -function pool( n ) { - var out; - var i; - - out = []; - for ( i = 0; i < n+1; i++ ) { - out.push( [] ); - } - return out; -} - - -// EXPORTS // - -module.exports = pool; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 95667c7..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'highWaterMark': 1024 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '01H2V,FD', options ) ); - } - if ( hasOwnProp( options, 'highWaterMark' ) ) { - opts.highWaterMark = options.highWaterMark; - if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( '01H2t,G9', 'highWaterMark', opts.highWaterMark ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index e21a43e..bd7b179 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Typed array pool.", "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,76 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessors": "^0.1.0", - "@stdlib/array-buffer": "^0.1.0", - "@stdlib/array-dtype": "^0.1.0", - "@stdlib/array-typed-ctors": "^0.1.0", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-arraybuffer": "^0.1.1", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-complex128array": "^0.1.0", - "@stdlib/assert-is-complex64array": "^0.1.0", - "@stdlib/assert-is-nonnegative-integer": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/assert-is-string": "^0.1.1", - "@stdlib/assert-is-typed-array-like": "^0.1.0", - "@stdlib/math-base-special-ceil": "^0.1.0", - "@stdlib/math-base-special-ceil2": "^0.1.0", - "@stdlib/math-base-special-floor": "^0.1.0", - "@stdlib/math-base-special-log2": "^0.1.0", - "@stdlib/math-base-special-min": "^0.1.1", - "@stdlib/strided-base-reinterpret-complex128": "^0.1.0", - "@stdlib/strided-base-reinterpret-complex64": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.1.0", - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-float32": "^0.1.0", - "@stdlib/array-float64": "^0.1.0", - "@stdlib/array-int16": "^0.1.0", - "@stdlib/array-int32": "^0.1.0", - "@stdlib/array-int8": "^0.1.0", - "@stdlib/array-uint16": "^0.1.0", - "@stdlib/array-uint32": "^0.1.0", - "@stdlib/array-uint8": "^0.1.0", - "@stdlib/array-uint8c": "^0.1.0", - "@stdlib/assert-instance-of": "^0.1.1", - "@stdlib/assert-is-complex-typed-array": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-typed-array": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/complex-float32": "^0.1.0", - "@stdlib/complex-float64": "^0.1.0", - "@stdlib/complex-imag": "^0.1.0", - "@stdlib/complex-imagf": "^0.1.0", - "@stdlib/complex-real": "^0.1.0", - "@stdlib/complex-realf": "^0.1.0", - "@stdlib/math-base-special-pow": "^0.1.0", - "@stdlib/random-base-randu": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..db0d2a2 --- /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 0566527..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,1797 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var typedarraypool = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -}); diff --git a/test/test.factory.js b/test/test.factory.js deleted file mode 100644 index 396aee2..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,2240 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function (no options)', function test( t ) { - t.strictEqual( typeof factory(), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - t.strictEqual( typeof factory( {} ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided a `highWaterMark` option which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (length)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a function which returns a typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, length)', function test( t ) { - var typedarraypool = factory(); - var arr; - - arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a `malloc` method which is a circular reference', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - var buf; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the returned function is a property which returns the pool\'s high water mark', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function supports specifying a high water mark which limits the total amount of memory a pool can allocate', function test( t ) { - var typedarraypool; - var arr1; - var arr2; - - typedarraypool = factory({ - 'highWaterMark': 64 // bytes - }); - - typedarraypool.clear(); - - arr1 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr1.length, 8, 'returns expected value' ); - t.strictEqual( arr1.byteLength, 64, 'returns expected value' ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - typedarraypool.free( arr1 ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Create an array which is less than or equal to the high water mark: - arr2 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr2.length, 8, 'returns expected value' ); - t.strictEqual( arr2.byteLength, 64, 'returns expected value' ); - - typedarraypool.free( arr2 ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a property which returns the total number of accumulated bytes', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var typedarraypool; - var arrs; - var i; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 54aa5ee..0000000 --- a/test/test.js +++ /dev/null @@ -1,1797 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var typedarraypool = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -}); From c759e56d10bab6a060eff7d9d01d925ded0c41cc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 18:09:05 +0000 Subject: [PATCH 046/103] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index edfecbe..ae28056 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -34,7 +34,7 @@ var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); var accessors = require( '@stdlib/array-base-accessors' ); var adtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ArrayBuffer = require( '@stdlib/array-buffer' ); var ceil = require( '@stdlib/math-base-special-ceil' ); var floor = require( '@stdlib/math-base-special-floor' ); @@ -226,7 +226,7 @@ function factory( options ) { } ctor = ctors( dtype ); if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '01H2Y,KZ', dtype ) ); } if ( nargs <= 0 ) { return new ctor( 0 ); @@ -263,7 +263,7 @@ function factory( options ) { } return out; } - throw new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) ); + throw new TypeError( format( '01H2r,N0', arguments[ 0 ] ) ); } /** @@ -329,7 +329,7 @@ function factory( options ) { if ( isTypedArrayLike( buf ) && buf.buffer ) { buf = buf.buffer; } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) ); + throw new TypeError( format( '01H2s,N1', buf ) ); } if ( buf.byteLength > 0 ) { n = floor( log2( buf.byteLength ) ); diff --git a/lib/validate.js b/lib/validate.js index ce54890..95667c7 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '01H2V,FD', options ) ); } if ( hasOwnProp( options, 'highWaterMark' ) ) { opts.highWaterMark = options.highWaterMark; if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) ); + return new TypeError( format( '01H2t,G9', 'highWaterMark', opts.highWaterMark ) ); } } return null; diff --git a/package.json b/package.json index f95cb14..2110704 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "@stdlib/math-base-special-min": "^0.1.1", "@stdlib/strided-base-reinterpret-complex128": "^0.1.1", "@stdlib/strided-base-reinterpret-complex64": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From 25e1eba8e7f8b1e3f1461b295b146676b5fc975d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 3 Nov 2023 02:52:35 +0000 Subject: [PATCH 047/103] Remove files --- index.d.ts | 359 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6541 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 c6a3785..0000000 --- a/index.d.ts +++ /dev/null @@ -1,359 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; -import ArrayBuffer = require( '@stdlib/array-buffer' ); - -/** -* Typed array or null. -*/ -type TypedArrayOrNull = RealOrComplexTypedArray | null; - -/** -* Interface defining pool options. -*/ -interface Options { - /** - * Maximum total memory which can be allocated. - */ - highWaterMark?: number; -} - -/** -* Pool interface. -*/ -interface Pool { - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr = typedarraypool(); - * // returns [] - * - * @example - * var arr = typedarraypool( 'float32' ); - * // returns [] - */ - ( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * // Allocate an array of doubles: - * var arr = typedarraypool( 5, 'float64' ); - * // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * typedarraypool.free( arr ); - * - * @example - * var arr1 = typedarraypool( [ 0.5, 0.5, 0.5 ] ); - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * @example - * var arr1 = [ 0.5, 0.5, 0.5 ]; - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - */ - ( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc(); - * // returns [] - * - * var arr2 = typedarraypool.calloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param length - typed array length - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc( 5 ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * var arr2 = typedarraypool.calloc( 5, 'uint8' ); - * // returns [ 0, 0, 0, 0, 0 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( length: number, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc(); - * // returns [] - * - * var arr2 = typedarraypool.malloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc( 5 ); - * // returns - * - * var arr2 = typedarraypool.malloc( 5, 'uint8' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 5.0, -3.0, 2.0 ] ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr2 = typedarraypool.malloc( arr1 ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr3 = typedarraypool.malloc( arr1, 'int32' ); - * // returns [ 5, -3, 2 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * typedarraypool.free( arr3 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ] ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * var arr2 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ], 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Frees a typed array or typed array buffer for use in a future allocation. - * - * @param buf - typed array or typed array buffer to free - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array for use in a future allocation: - * typedarraypool.free( arr ); - * - * // Create another typed array: - * arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array buffer for use in a future allocation: - * typedarraypool.free( arr.buffer ); - */ - free( buf: RealOrComplexTypedArray | ArrayBuffer ): void; - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr ); - * - * // ... - * - * // Clear all freed buffers: - * typedarraypool.clear(); - */ - clear(): void; - - /** - * Read-only property returning the pool's high water mark. - * - * ## Notes - * - * - Once a high water mark is reached, typed array allocation fails. - * - * @example - * var limit = typedarraypool.highWaterMark; - * // returns - */ - readonly highWaterMark: number; - - /** - * Read-only property returning the total number of allocated bytes. - * - * @example - * var arr = typedarraypool( 5, 'float64' ); - * - * var nbytes = typedarraypool.nbytes; - * // returns - */ - readonly nbytes: number; - - /** - * Creates a typed array pool. - * - * @param options - pool options - * @param options.highWaterMark - maximum total memory which can be allocated - * @throws must provide valid options - * @returns allocator - * - * @example - * var allocator = typedarraypool.factory(); - * - * // Allocate an array of doubles: - * var arr = allocator( 5, 'float64' ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * allocator.free( arr ); - */ - factory( options?: Options ): Pool; -} - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @param arg - an array length or an array-like object -* @param dtype - data type (default: 'float64') -* @returns typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -declare var typedarraypool: Pool; - - -// EXPORTS // - -export = typedarraypool; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c29a166..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.1.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessors@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.1.0-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.1.0-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.1.0-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.1.0-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.1.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";function k(e,t){return y(t)?w(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(c("01H2t,G9","highWaterMark",e.highWaterMark)):null:new TypeError(c("01H2V,FD",t))}function M(e){var t,r;for(t=[],r=0;rH.highWaterMark?null:(t=new j(e),w+=e,t)}function G(e,t,r){var s;return 0===t?new e(0):null===(s=F(u(t)*W[r]))?s:new e(s,0,t)}function K(){var e,i,n,l,j,v,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(n=d(i)))throw new TypeError(c("01H2Y,KZ",i));if(e<=0)return new n(0);if(r(arguments[0]))return G(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,m(l)?l=h(l,0):o(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=G(n,u,i)))return j;if(L(j)||T(j))return j.set(l),j;for(g=p(f(l)).accessors[0],v=p(i).accessors[1],b=0;b0){for(t=g(b(e.byteLength)),t=x(E.length-1,t),r=E[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '01H2Y,KZ', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = accessors( adtype( arr ) ).accessors[ 0 ];\n\t\t\tset = accessors( dtype ).accessors[ 1 ];\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '01H2r,N0', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( '01H2s,N1', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","accessors","adtype","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;ywEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,WAAY,gBAAiBP,EAAKI,gBAG3D,KARC,IAAIE,UAAWC,EAAQ,WAAYN,GAS5C,CC/BA,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,iHCaIG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EC/EO,CACNI,cAAiB,kBD+EbkB,UAAUC,SACdF,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOgB,EAAYC,EAAMC,EAAM1B,EAAKI,iBACpCgB,EAAS,EAETO,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB5B,EAAKI,eAC3C4B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOb,CACP,CASD,SAASc,EAAazB,GACrB,IAAI0B,EACAxB,EAMJ,OAHAA,EAAIe,EAAMjB,IAGDD,EAAKe,QAAUf,EAAMG,GAAIY,OAC1Bf,EAAMG,GAAIyB,MAGbhB,EAAOX,EAAIT,EAAKI,cACb,MAER+B,EAAM,IAAIE,EAAa5B,GAGvBW,GAAUX,EAEH0B,EACP,CAWD,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,EACzB,CAkBD,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAtB,EACAP,EACAmC,EACAC,EACAN,EACA7B,EAUJ,GALC8B,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAOzB,EAAO2B,IAEb,MAAM,IAAInC,UAAWC,EAAQ,WAAYkC,IAE1C,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKlC,EAAsBiB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAvB,EAAMK,UAAW,IACPC,OACL0B,EAAmBhC,GACvBA,EAAMiC,EAAgBjC,EAAK,GAChBkC,EAAkBlC,GAC7BA,EAAMmC,EAAenC,EAAK,GACf,WAAWoC,KAAMZ,KAE5BD,GAAO,GAGK,QADb9B,EAAM4B,EAAYC,EAAMC,EAAKC,IAE5B,OAAO/B,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAImC,IAAK5B,GACFP,EAKR,IAFAoC,EAAMQ,EAAWC,EAAQtC,IAAQqC,UAAW,GAC5CT,EAAMS,EAAWb,GAAQa,UAAW,GAC9B3C,EAAI,EAAGA,EAAI6B,EAAK7B,IACrBkC,EAAKnC,EAAKC,EAAGmC,EAAK7B,EAAKN,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,WAAYe,UAAW,IACpD,CAgBD,SAASO,IACR,IAAIe,EACAlC,EACA8C,EACA7C,EAUJ,GAAa,QANZD,EADc,KADfkC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCkC,EADItC,EAAiBR,GACfwC,EAAgBxC,EAAK,GAChBM,EAAgBN,GACrB0C,EAAe1C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAI6C,EAAIjC,OAAQZ,IAC5B6C,EAAK7C,GAAM,EAGb,OAAOD,CACP,CAcD,SAASoB,EAAMK,GACd,IAAI1B,EACAgD,EACA9C,EACJ,GAAK+C,EAAkBvB,IAASA,EAAIwB,OACnCxB,EAAMA,EAAIwB,YACJ,IAAMC,EAAezB,GAC3B,MAAM,IAAI7B,UAAWC,EAAQ,WAAY4B,IAE1C,GAAKA,EAAI0B,WAAa,EAAI,CAQzB,IAPApD,EAAIqD,EAAOpC,EAAMS,EAAI0B,aAGrBpD,EAAIsD,EAAKvD,EAAKe,OAAO,EAAGd,GAGxBgD,EAAIjD,EAAMC,GACJE,EAAI,EAAGA,EAAI8C,EAAElC,OAAQZ,IAC1B,GAAK8C,EAAG9C,KAAQwB,EACf,OAAO,EAITsB,EAAE7C,KAAMuB,EACR,CACD,OAAO,CACP,CAOD,SAASJ,IACR,IAAIpB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKe,OAAQZ,IAC7BH,EAAMG,GAAIY,OAAS,EAEpBH,EAAS,CACT,CACF,CEnTG,IAAC4C,EAAiB7C,ICPrBQ,EAAAsC,EAAA,UAAA9C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index db0d2a2..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From a20d22c34b433ddc3a5c178f0689595b911e0bd8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 3 Nov 2023 02:55:45 +0000 Subject: [PATCH 048/103] 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 | 43 +- benchmark/benchmark.calloc.js | 246 - benchmark/benchmark.factory.js | 71 - benchmark/benchmark.js | 246 - benchmark/benchmark.length.complex128.js | 102 - benchmark/benchmark.length.complex64.js | 102 - benchmark/benchmark.length.float32.js | 102 - benchmark/benchmark.length.float64.js | 102 - benchmark/benchmark.length.int16.js | 102 - benchmark/benchmark.length.int32.js | 102 - benchmark/benchmark.length.int8.js | 102 - benchmark/benchmark.length.uint16.js | 102 - benchmark/benchmark.length.uint32.js | 102 - benchmark/benchmark.length.uint8.js | 102 - benchmark/benchmark.length.uint8c.js | 102 - benchmark/benchmark.malloc.js | 246 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 347 -- docs/types/test.ts | 193 - examples/index.js | 80 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/bytes_per_element.json | 13 - lib/defaults.js | 42 - lib/factory.js | 370 -- lib/index.js | 56 - lib/main.js | 63 - lib/pool.js | 44 - lib/validate.js | 66 - package.json | 97 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 2240 -------- test/test.js | 1797 ------ 62 files changed, 6206 insertions(+), 10638 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.calloc.js delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.complex128.js delete mode 100644 benchmark/benchmark.length.complex64.js delete mode 100644 benchmark/benchmark.length.float32.js delete mode 100644 benchmark/benchmark.length.float64.js delete mode 100644 benchmark/benchmark.length.int16.js delete mode 100644 benchmark/benchmark.length.int32.js delete mode 100644 benchmark/benchmark.length.int8.js delete mode 100644 benchmark/benchmark.length.uint16.js delete mode 100644 benchmark/benchmark.length.uint32.js delete mode 100644 benchmark/benchmark.length.uint8.js delete mode 100644 benchmark/benchmark.length.uint8c.js delete mode 100644 benchmark/benchmark.malloc.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/bytes_per_element.json delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/pool.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index d8a6621..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-11-01T05:58:05.579Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ea35f20..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/array/pool) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6f7c875..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/array/pool) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 4f5a65c..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -493,7 +492,7 @@ console.log( 'nbytes: %d', typedarray.nbytes ); ## 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]. @@ -559,7 +558,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm diff --git a/benchmark/benchmark.calloc.js b/benchmark/benchmark.calloc.js deleted file mode 100644 index e5a1c77..0000000 --- a/benchmark/benchmark.calloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':calloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index f7cd676..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = typedarray.factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:highWaterMark', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'highWaterMark': 0 - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.highWaterMark = i; - f = typedarray.factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a023d2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.complex128.js b/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 47b623b..0000000 --- a/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex64.js b/benchmark/benchmark.length.complex64.js deleted file mode 100644 index 40a412b..0000000 --- a/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float32.js b/benchmark/benchmark.length.float32.js deleted file mode 100644 index 0227ed7..0000000 --- a/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float64.js b/benchmark/benchmark.length.float64.js deleted file mode 100644 index 2dbac1c..0000000 --- a/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int16.js b/benchmark/benchmark.length.int16.js deleted file mode 100644 index e2a8adc..0000000 --- a/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int32.js b/benchmark/benchmark.length.int32.js deleted file mode 100644 index e4df0aa..0000000 --- a/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int8.js b/benchmark/benchmark.length.int8.js deleted file mode 100644 index 7ceac11..0000000 --- a/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint16.js b/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 9a532b6..0000000 --- a/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint32.js b/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 98f2d7f..0000000 --- a/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8.js b/benchmark/benchmark.length.uint8.js deleted file mode 100644 index 8359249..0000000 --- a/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8c.js b/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index d47d023..0000000 --- a/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.malloc.js b/benchmark/benchmark.malloc.js deleted file mode 100644 index d4eea72..0000000 --- a/benchmark/benchmark.malloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':malloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 9689761..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/array/pool" -%% click B href "https://github.com/stdlib-js/array-pool/tree/main" -%% click C href "https://github.com/stdlib-js/array-pool/tree/production" -%% click D href "https://github.com/stdlib-js/array-pool/tree/esm" -%% click E href "https://github.com/stdlib-js/array-pool/tree/deno" -%% click F href "https://github.com/stdlib-js/array-pool/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/pool -[production-url]: https://github.com/stdlib-js/array-pool/tree/production -[deno-url]: https://github.com/stdlib-js/array-pool/tree/deno -[umd-url]: https://github.com/stdlib-js/array-pool/tree/umd -[esm-url]: https://github.com/stdlib-js/array-pool/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 5160b6f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import typedarraypool from '../docs/types/index'; -export = typedarraypool; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 9d31d69..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var l=function(n,i){return function(){return i||n((i={exports:{}}).exports,i),i.exports}};var k=l(function(kr,M){ -function D(){return{highWaterMark:9007199254740992}}M.exports=D -});var E=l(function(Ar,W){ -var G=require('@stdlib/assert-is-plain-object/dist'),H=require('@stdlib/assert-has-own-property/dist'),J=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,A=require('@stdlib/error-tools-fmtprodmsg/dist');function K(n,i){return G(i)?H(i,"highWaterMark")&&(n.highWaterMark=i.highWaterMark,!J(n.highWaterMark))?new TypeError(A('01H2t',"highWaterMark",n.highWaterMark)):null:new TypeError(A('01H2V',i));}W.exports=K -});var C=l(function(Wr,T){ -function Q(n){var i,u;for(i=[],u=0;uv.highWaterMark?null:(e=new ur(r),i+=r,e)}function d(r,e,t){var a;return e===0?new r(0):(a=_(lr(e)*hr[t]),a===null?a:new r(a,0,e))}function s(){var r,e,t,a,o,x,w,c,f;if(r=arguments.length,r&&X(arguments[r-1])?(r-=1,e=arguments[r]):e="float64",t=y(e),t===null)throw new TypeError(m('01H2Y',e));if(r<=0)return new t(0);if(Z(arguments[0]))return d(t,arguments[0],e);if($(arguments[0])){if(a=arguments[0],c=a.length,tr(a)?a=P(a,0):ar(a)?a=b(a,0):/^complex/.test(e)&&(c/=2),o=d(t,c,e),o===null)return o;if(L(o)||N(o))return o.set(a),o;for(w=B(nr(a)).accessors[0],x=B(e).accessors[1],f=0;f0){for(e=or(p(r.byteLength)),e=vr(u.length-1,e),t=u[e],a=0;a[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = accessors( adtype( arr ) ).accessors[ 0 ];\n\t\t\tset = accessors( dtype ).accessors[ 1 ];\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nmodule.exports = typedarraypool;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* var typedarraypool = require( '@stdlib/array-pool' );\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,cAAiB,gBAClB,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,eAAgB,IACzCD,EAAK,cAAgBC,EAAQ,cACxB,CAACJ,EAAsBG,EAAK,aAAc,GACvC,IAAI,UAAWF,EAAQ,2EAA4E,gBAAiBE,EAAK,aAAc,CAAE,EAG3I,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cA6BA,SAASC,EAAM,EAAI,CAClB,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAI,EAAE,EAAGA,IACrBD,EAAI,KAAM,CAAC,CAAE,EAEd,OAAOA,CACR,CAKAF,EAAO,QAAUC,IC3CjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,QAAW,EACX,QAAW,EACX,MAAS,EACT,MAAS,EACT,KAAQ,EACR,OAAU,EACV,OAAU,EACV,MAAS,EACT,OAAU,EACT,UAAa,EACb,WAAc,EAChB,ICZA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAe,QAAS,8BAA+B,EACvDC,GAAmB,QAAS,oCAAqC,EACjEC,GAAgB,QAAS,+BAAgC,EACzDC,GAAmB,QAAS,kCAAmC,EAC/DC,GAAoB,QAAS,mCAAoC,EACjEC,EAAc,QAAS,uDAAwD,EAC/EC,GAAsB,QAAS,uDAAwD,EACvFC,EAAQ,QAAS,2BAA4B,EAC7CC,EAAgB,QAAS,4CAA6C,EACtEC,EAAiB,QAAS,6CAA8C,EACxEC,EAAY,QAAS,8BAA+B,EACpDC,GAAS,QAAS,qBAAsB,EACxCC,EAAS,QAAS,uBAAwB,EAC1CC,GAAc,QAAS,sBAAuB,EAC9CC,GAAO,QAAS,gCAAiC,EACjDC,GAAQ,QAAS,iCAAkC,EACnDC,GAAQ,QAAS,iCAAkC,EACnDC,EAAO,QAAS,gCAAiC,EACjDC,GAAM,QAAS,+BAAgC,EAC/CC,GAAW,IACXC,GAAW,IACXC,GAAa,IACbC,GAAoB,IAKpBC,GAAiBhB,EAAO,WAAY,EACpCiB,GAAkBjB,EAAO,YAAa,EAY1C,SAASkB,EAAgBC,EAAM,CAC9B,OAASA,aAAeH,EACzB,CASA,SAASI,EAAiBD,EAAM,CAC/B,OAASA,aAAeF,EACzB,CA6BA,SAASI,GAASC,EAAU,CAC3B,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,EAAOb,GAAS,EACX,UAAU,SACdc,EAAMb,GAAUY,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAAF,EAAOV,GAAYP,GAAMG,EAAMe,EAAK,aAAc,CAAE,CAAE,EACtDF,EAAS,EAETzB,EAAa6B,EAAQ,SAAUA,CAAO,EACtC7B,EAAa6B,EAAQ,SAAUC,CAAO,EACtC9B,EAAa6B,EAAQ,OAAQE,CAAK,EAClC/B,EAAa6B,EAAQ,QAASG,CAAM,EACpChC,EAAa6B,EAAQ,gBAAiBF,EAAK,aAAc,EACzD1B,GAAqB4B,EAAQ,SAAUI,CAAS,EAEzCJ,EAQP,SAASI,GAAW,CACnB,OAAOR,CACR,CASA,SAASS,EAAaC,EAAI,CACzB,IAAIC,EACAC,EAMJ,OAHAA,EAAIzB,EAAMuB,CAAE,EAGPE,EAAIX,EAAK,QAAUA,EAAMW,CAAE,EAAE,OAC1BX,EAAMW,CAAE,EAAE,IAAI,EAGjBZ,EAAOU,EAAIR,EAAK,cACb,MAERS,EAAM,IAAI5B,GAAa2B,CAAE,EAGzBV,GAAUU,EAEHC,EACR,CAWA,SAASE,EAAYC,EAAMC,EAAKC,EAAQ,CACvC,IAAIL,EACJ,OAAKI,IAAQ,EACL,IAAID,EAAM,CAAE,GAEpBH,EAAMF,EAAavB,GAAO6B,CAAI,EAAEvB,GAAmBwB,CAAM,CAAE,EACtDL,IAAQ,KACLA,EAED,IAAIG,EAAMH,EAAK,EAAGI,CAAI,EAC9B,CAkBA,SAASX,GAAS,CACjB,IAAIa,EACAD,EACAF,EACAlB,EACAsB,EACAC,EACAC,EACAL,EACAH,EAUJ,GARAK,EAAQ,UAAU,OACbA,GAASjD,EAAU,UAAWiD,EAAM,CAAE,CAAE,GAC5CA,GAAS,EACTD,EAAQ,UAAWC,CAAM,GAEzBD,EAAQ,UAETF,EAAOrC,EAAOuC,CAAM,EACfF,IAAS,KACb,MAAM,IAAI,UAAWhC,EAAQ,sEAAuEkC,CAAM,CAAE,EAE7G,GAAKC,GAAS,EACb,OAAO,IAAIH,EAAM,CAAE,EAGpB,GAAK7C,EAAsB,UAAW,CAAE,CAAE,EACzC,OAAO4C,EAAYC,EAAM,UAAW,CAAE,EAAGE,CAAM,EAGhD,GAAK9C,EAAc,UAAW,CAAE,CAAE,EAAI,CAYrC,GAXA0B,EAAM,UAAW,CAAE,EACnBmB,EAAMnB,EAAI,OACLtB,GAAmBsB,CAAI,EAC3BA,EAAMjB,EAAgBiB,EAAK,CAAE,EAClBvB,GAAkBuB,CAAI,EACjCA,EAAMlB,EAAekB,EAAK,CAAE,EACjB,WAAW,KAAMoB,CAAM,IAElCD,GAAO,GAERG,EAAML,EAAYC,EAAMC,EAAKC,CAAM,EAC9BE,IAAQ,KACZ,OAAOA,EAER,GAAKrB,EAAiBqB,CAAI,GAAKvB,EAAgBuB,CAAI,EAClD,OAAAA,EAAI,IAAKtB,CAAI,EACNsB,EAKR,IAFAE,EAAMxC,EAAWC,GAAQe,CAAI,CAAE,EAAE,UAAW,CAAE,EAC9CuB,EAAMvC,EAAWoC,CAAM,EAAE,UAAW,CAAE,EAChCJ,EAAI,EAAGA,EAAIG,EAAKH,IACrBO,EAAKD,EAAKN,EAAGQ,EAAKxB,EAAKgB,CAAE,CAAE,EAE5B,OAAOM,CACR,CACA,MAAM,IAAI,UAAWpC,EAAQ,wGAAyG,UAAW,CAAE,CAAE,CAAE,CACxJ,CAgBA,SAASuB,GAAS,CACjB,IAAIY,EACAC,EACAG,EACAT,EAUJ,GARAK,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAMd,EAAO,EACFa,IAAU,EACrBC,EAAMd,EAAQ,UAAW,CAAE,CAAE,EAE7Bc,EAAMd,EAAQ,UAAW,CAAE,EAAG,UAAW,CAAE,CAAE,EAEzCc,IAAQ,KASZ,IAPKrB,EAAiBqB,CAAI,EACzBG,EAAM1C,EAAgBuC,EAAK,CAAE,EAClBvB,EAAgBuB,CAAI,EAC/BG,EAAM3C,EAAewC,EAAK,CAAE,EAE5BG,EAAMH,EAEDN,EAAI,EAAGA,EAAIS,EAAI,OAAQT,IAC5BS,EAAKT,CAAE,EAAI,EAGb,OAAOM,CACR,CAcA,SAASZ,EAAMK,EAAM,CACpB,IAAID,EACAY,EACAV,EACJ,GAAKzC,GAAkBwC,CAAI,GAAKA,EAAI,OACnCA,EAAMA,EAAI,eACC,CAACvC,GAAeuC,CAAI,EAC/B,MAAM,IAAI,UAAW7B,EAAQ,4EAA6E6B,CAAI,CAAE,EAEjH,GAAKA,EAAI,WAAa,EAAI,CAQzB,IAPAD,EAAIzB,GAAOE,EAAMwB,EAAI,UAAW,CAAE,EAGlCD,EAAItB,GAAKa,EAAK,OAAO,EAAGS,CAAE,EAG1BY,EAAIrB,EAAMS,CAAE,EACNE,EAAI,EAAGA,EAAIU,EAAE,OAAQV,IAC1B,GAAKU,EAAGV,CAAE,IAAMD,EACf,MAAO,GAITW,EAAE,KAAMX,CAAI,CACb,CACA,MAAO,EACR,CAOA,SAASJ,GAAQ,CAChB,IAAIK,EACJ,IAAMA,EAAI,EAAGA,EAAIX,EAAK,OAAQW,IAC7BX,EAAMW,CAAE,EAAE,OAAS,EAEpBZ,EAAS,CACV,CACD,CAKAjC,EAAO,QAAU+B,KCjXjB,IAAAyB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAU,IAmCVC,GAAiBD,GAAQ,EAK7BD,EAAO,QAAUE,KCnBjB,IAAIC,GAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,GAAU,IAKdF,GAAaC,EAAM,UAAWC,EAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isNonNegativeInteger", "format", "validate", "opts", "options", "require_pool", "__commonJSMin", "exports", "module", "pool", "out", "i", "require_bytes_per_element", "__commonJSMin", "exports", "module", "require_factory", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isCollection", "isTypedArrayLike", "isArrayBuffer", "isComplex64Array", "isComplex128Array", "setReadOnly", "setReadOnlyAccessor", "ctors", "reinterpret64", "reinterpret128", "accessors", "adtype", "format", "ArrayBuffer", "ceil", "floor", "ceil2", "log2", "min", "defaults", "validate", "createPool", "BYTES_PER_ELEMENT", "Complex64Array", "Complex128Array", "isCmplx64Array", "arr", "isCmplx128Array", "factory", "options", "nbytes", "pool", "opts", "err", "malloc", "calloc", "free", "clear", "getBytes", "arraybuffer", "n", "buf", "i", "typedarray", "ctor", "len", "dtype", "nargs", "out", "set", "get", "tmp", "p", "require_main", "__commonJSMin", "exports", "module", "factory", "typedarraypool", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5244595..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,347 +0,0 @@ - -{{alias}}( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - Memory is **uninitialized**, which means that the contents of a returned - typed array may contain sensitive contents. - - The function supports the following data types: - - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - The default typed array data type is `float64`. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}() - [] - > arr = {{alias}}( 'float32' ) - [] - - -{{alias}}( length[, dtype] ) - Returns an uninitialized typed array having a specified length from a typed - array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > arr = {{alias}}( 5, 'int32' ) - - - -{{alias}}( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - This method shares the same security vulnerabilities mentioned above. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc() - - > arr = {{alias}}.malloc( 'float32' ) - - - -{{alias}}.malloc( length[, dtype] ) - Returns a typed array having a specified length from a typed array memory - pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc( 5 ) - - > arr = {{alias}}.malloc( 5, 'int32' ) - - - -{{alias}}.malloc( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}.malloc( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.calloc( [dtype] ) - Returns a zero-initialized typed array from a typed array memory pool. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc() - [] - > arr = {{alias}}.calloc( 'float32' ) - [] - - -{{alias}}.calloc( length[, dtype] ) - Returns a zero-initialized typed array having a specified length from a - typed array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}.calloc( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}.free( buf ) - Frees a typed array or typed array buffer for use in a future allocation. - - Parameters - ---------- - buf: TypedArray|ArrayBuffer - Typed array or typed array buffer to free. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ) - - -{{alias}}.clear() - Clears the typed array pool allowing garbage collection of previously - allocated (and currently free) array buffers. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - > {{alias}}.clear() - - -{{alias}}.highWaterMark - Read-only property returning the pool's high water mark. - - Once a high water mark is reached, typed array allocation fails. - - Examples - -------- - > {{alias}}.highWaterMark - - -{{alias}}.nbytes - Read-only property returning the total number of allocated bytes. - - The returned value is the total accumulated value. Hence, anytime a pool - must allocate a new array buffer (i.e., more memory), the pool increments - this value. - - The only time this value is decremented is when a pool is cleared. - - This behavior means that, while allocated buffers which are never freed may, - in fact, be garbage collected, they continue to count against the high water - mark limit. - - Accordingly, you should *always* free allocated buffers in order to prevent - the pool from believing that non-freed buffers are continually in use. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.nbytes - - -{{alias}}.factory( [options] ) - Creates a typed array pool. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.highWaterMark: integer (optional) - Maximum total memory (in bytes) which can be allocated. - - Returns - ------- - fcn: Function - Function for creating typed arrays from a typed array memory pool. - - Examples - -------- - > var pool = {{alias}}.factory(); - > var arr1 = pool( 3, 'float64' ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 1014bba..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,193 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* tslint:disable:no-empty */ -/* tslint:disable:no-unused-expression */ - -import typedarraypool = require( './index' ); - - -// TESTS // - -// The function returns a typed array or null... -{ - typedarraypool(); // $ExpectType TypedArrayOrNull - typedarraypool( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the function is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool( true ); // $ExpectError - typedarraypool( false ); // $ExpectError - typedarraypool( null ); // $ExpectError - typedarraypool( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized data type... -{ - typedarraypool( 4, true ); // $ExpectError - typedarraypool( 4, false ); // $ExpectError - typedarraypool( 4, null ); // $ExpectError - typedarraypool( 4, 'abc' ); // $ExpectError - typedarraypool( 4, 123 ); // $ExpectError - typedarraypool( 4, [] ); // $ExpectError - typedarraypool( 4, {} ); // $ExpectError - typedarraypool( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an incorrect number of arguments... -{ - typedarraypool( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `malloc` method which returns a typed array or null... -{ - typedarraypool.malloc(); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.malloc( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `malloc` method is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool.malloc( true ); // $ExpectError - typedarraypool.malloc( false ); // $ExpectError - typedarraypool.malloc( null ); // $ExpectError - typedarraypool.malloc( {} ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.malloc( 4, true ); // $ExpectError - typedarraypool.malloc( 4, false ); // $ExpectError - typedarraypool.malloc( 4, null ); // $ExpectError - typedarraypool.malloc( 4, 'abc' ); // $ExpectError - typedarraypool.malloc( 4, 123 ); // $ExpectError - typedarraypool.malloc( 4, [] ); // $ExpectError - typedarraypool.malloc( 4, {} ); // $ExpectError - typedarraypool.malloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided an incorrect number of arguments... -{ - typedarraypool.malloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `calloc` method which returns a typed array or null... -{ - typedarraypool.calloc(); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `calloc` method is provided a first argument which is not a number... -{ - typedarraypool.calloc( 'abc' ); // $ExpectError - typedarraypool.calloc( true ); // $ExpectError - typedarraypool.calloc( false ); // $ExpectError - typedarraypool.calloc( null ); // $ExpectError - typedarraypool.calloc( {} ); // $ExpectError - typedarraypool.calloc( [] ); // $ExpectError - typedarraypool.calloc( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.calloc( 4, true ); // $ExpectError - typedarraypool.calloc( 4, false ); // $ExpectError - typedarraypool.calloc( 4, null ); // $ExpectError - typedarraypool.calloc( 4, 'abc' ); // $ExpectError - typedarraypool.calloc( 4, 123 ); // $ExpectError - typedarraypool.calloc( 4, [] ); // $ExpectError - typedarraypool.calloc( 4, {} ); // $ExpectError - typedarraypool.calloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided an incorrect number of arguments... -{ - typedarraypool.calloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `factory` method which returns a typed array pool.. -{ - typedarraypool.factory(); // $ExpectType Pool - typedarraypool.factory( { 'highWaterMark': 556 } ); // $ExpectType Pool -} - -// The compiler throws an error if the `factory` method is provided a `highWaterMark` option which is not a number... -{ - typedarraypool.factory( { 'highWaterMark': true } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': false } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': 'abc' } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': null } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': [] } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': {} } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an incorrect number of arguments... -{ - typedarraypool.factory( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` method which returns void... -{ - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.free( arr ); // $ExpectType void -} - -// The compiler throws an error if the `free` method is provided a first argument which is neither a typed array nor array buffer... -{ - typedarraypool.free( true ); // $ExpectError - typedarraypool.free( false ); // $ExpectError - typedarraypool.free( 123 ); // $ExpectError - typedarraypool.free( 'abc' ); // $ExpectError - typedarraypool.free( null ); // $ExpectError - typedarraypool.free( {} ); // $ExpectError - typedarraypool.free( ( x: number ): number => x ); // $ExpectError -} - -// Attached to the main export is a `clear` method which returns void... -{ - typedarraypool.clear(); // $ExpectType void -} - -// The compiler throws an error if the `clear` method is provided arguments... -{ - typedarraypool.clear( {} ); // $ExpectError - typedarraypool.clear( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `highWaterMark` property... -{ - typedarraypool.highWaterMark; // $ExpectType number -} - -// Attached to the main export is a `nbytes` property... -{ - typedarraypool.nbytes; // $ExpectType number -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 24a7846..0000000 --- a/examples/index.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 randu = require( '@stdlib/random-base-randu' ); -var typedarraypool = require( './../lib' ); - -// Create a typed array pool which can allocate at most 1GB: -var typedarray = typedarraypool.factory({ - 'highWaterMark': 1e9 -}); - -// Inspect the pool: -console.log( 'Max bytes: %d', typedarray.highWaterMark ); -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Allocate an array for storing double-precision floating-point numbers: -var arr1 = typedarray( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Fill the array... -var i; -for ( i = 0; i < arr1.length; i++ ) { - arr1[ i ] = randu(); -} - -// Inspect array contents: -console.log( arr1 ); - -// Free the array: -typedarray.free( arr1 ); - -// Allocate another array similar to the previous one: -var arr2 = typedarray( 5, 'float64' ); -// returns - -// Check that we have been returned a new typed array view: -console.log( arr2 === arr1 ); -// => false - -// Inspect array contents: -console.log( arr2 ); - -// Free the array: -typedarray.free( arr2 ); - -// Allocate an initialized array: -var arr3 = typedarray.calloc( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect array contents: -console.log( arr3 ); - -// Free the array: -typedarray.free( arr3 ); - -// Clear the pool: -typedarray.clear(); - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index de70cb0..c6a3785 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; import ArrayBuffer = require( '@stdlib/array-buffer' ); diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ceb156c --- /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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessors@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.1.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.1.0-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.1.1-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.1.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";function k(e,t){return y(t)?w(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(c("01H2t,G9","highWaterMark",e.highWaterMark)):null:new TypeError(c("01H2V,FD",t))}function M(e){var t,r;for(t=[],r=0;rH.highWaterMark?null:(t=new j(e),w+=e,t)}function G(e,t,r){var s;return 0===t?new e(0):null===(s=F(u(t)*W[r]))?s:new e(s,0,t)}function K(){var e,i,n,l,j,v,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(n=d(i)))throw new TypeError(c("01H2Y,KZ",i));if(e<=0)return new n(0);if(r(arguments[0]))return G(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,m(l)?l=h(l,0):o(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=G(n,u,i)))return j;if(L(j)||T(j))return j.set(l),j;for(g=p(f(l)).accessors[0],v=p(i).accessors[1],b=0;b0){for(t=g(b(e.byteLength)),t=x(E.length-1,t),r=E[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '01H2Y,KZ', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = accessors( adtype( arr ) ).accessors[ 0 ];\n\t\t\tset = accessors( dtype ).accessors[ 1 ];\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '01H2r,N0', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( '01H2s,N1', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","accessors","adtype","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;ywEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,WAAY,gBAAiBP,EAAKI,gBAG3D,KARC,IAAIE,UAAWC,EAAQ,WAAYN,GAS5C,CC/BA,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,iHCaIG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EC/EO,CACNI,cAAiB,kBD+EbkB,UAAUC,SACdF,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOgB,EAAYC,EAAMC,EAAM1B,EAAKI,iBACpCgB,EAAS,EAETO,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB5B,EAAKI,eAC3C4B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOb,CACP,CASD,SAASc,EAAazB,GACrB,IAAI0B,EACAxB,EAMJ,OAHAA,EAAIe,EAAMjB,IAGDD,EAAKe,QAAUf,EAAMG,GAAIY,OAC1Bf,EAAMG,GAAIyB,MAGbhB,EAAOX,EAAIT,EAAKI,cACb,MAER+B,EAAM,IAAIE,EAAa5B,GAGvBW,GAAUX,EAEH0B,EACP,CAWD,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,EACzB,CAkBD,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAtB,EACAP,EACAmC,EACAC,EACAN,EACA7B,EAUJ,GALC8B,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAOzB,EAAO2B,IAEb,MAAM,IAAInC,UAAWC,EAAQ,WAAYkC,IAE1C,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKlC,EAAsBiB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAvB,EAAMK,UAAW,IACPC,OACL0B,EAAmBhC,GACvBA,EAAMiC,EAAgBjC,EAAK,GAChBkC,EAAkBlC,GAC7BA,EAAMmC,EAAenC,EAAK,GACf,WAAWoC,KAAMZ,KAE5BD,GAAO,GAGK,QADb9B,EAAM4B,EAAYC,EAAMC,EAAKC,IAE5B,OAAO/B,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAImC,IAAK5B,GACFP,EAKR,IAFAoC,EAAMQ,EAAWC,EAAQtC,IAAQqC,UAAW,GAC5CT,EAAMS,EAAWb,GAAQa,UAAW,GAC9B3C,EAAI,EAAGA,EAAI6B,EAAK7B,IACrBkC,EAAKnC,EAAKC,EAAGmC,EAAK7B,EAAKN,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,WAAYe,UAAW,IACpD,CAgBD,SAASO,IACR,IAAIe,EACAlC,EACA8C,EACA7C,EAUJ,GAAa,QANZD,EADc,KADfkC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCkC,EADItC,EAAiBR,GACfwC,EAAgBxC,EAAK,GAChBM,EAAgBN,GACrB0C,EAAe1C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAI6C,EAAIjC,OAAQZ,IAC5B6C,EAAK7C,GAAM,EAGb,OAAOD,CACP,CAcD,SAASoB,EAAMK,GACd,IAAI1B,EACAgD,EACA9C,EACJ,GAAK+C,EAAkBvB,IAASA,EAAIwB,OACnCxB,EAAMA,EAAIwB,YACJ,IAAMC,EAAezB,GAC3B,MAAM,IAAI7B,UAAWC,EAAQ,WAAY4B,IAE1C,GAAKA,EAAI0B,WAAa,EAAI,CAQzB,IAPApD,EAAIqD,EAAOpC,EAAMS,EAAI0B,aAGrBpD,EAAIsD,EAAKvD,EAAKe,OAAO,EAAGd,GAGxBgD,EAAIjD,EAAMC,GACJE,EAAI,EAAGA,EAAI8C,EAAElC,OAAQZ,IAC1B,GAAK8C,EAAG9C,KAAQwB,EACf,OAAO,EAITsB,EAAE7C,KAAMuB,EACR,CACD,OAAO,CACP,CAOD,SAASJ,IACR,IAAIpB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKe,OAAQZ,IAC7BH,EAAMG,GAAIY,OAAS,EAEpBH,EAAS,CACT,CACF,CEnTG,IAAC4C,EAAiB7C,ICPrBQ,EAAAsC,EAAA,UAAA9C"} \ No newline at end of file diff --git a/lib/bytes_per_element.json b/lib/bytes_per_element.json deleted file mode 100644 index f97fe70..0000000 --- a/lib/bytes_per_element.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "float64": 8, - "float32": 4, - "int16": 2, - "int32": 4, - "int8": 1, - "uint16": 2, - "uint32": 4, - "uint8": 1, - "uint8c": 1, - "complex64": 8, - "complex128": 16 -} diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index a421711..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +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'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'highWaterMark': 9007199254740992 - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index ae28056..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,370 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var isComplex64Array = require( '@stdlib/assert-is-complex64array' ); -var isComplex128Array = require( '@stdlib/assert-is-complex128array' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var ctors = require( '@stdlib/array-typed-ctors' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var accessors = require( '@stdlib/array-base-accessors' ); -var adtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil = require( '@stdlib/math-base-special-ceil' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); -var log2 = require( '@stdlib/math-base-special-log2' ); -var min = require( '@stdlib/math-base-special-min' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var createPool = require( './pool.js' ); -var BYTES_PER_ELEMENT = require( './bytes_per_element.json' ); - - -// VARIABLES // - -var Complex64Array = ctors( 'complex64' ); -var Complex128Array = ctors( 'complex128' ); - - -// FUNCTIONS // - -/** -* Tests whether an array is a single-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a single-precision complex floating-point number array -*/ -function isCmplx64Array( arr ) { - return ( arr instanceof Complex64Array ); -} - -/** -* Tests whether an array is a double-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a double-precision complex floating-point number array -*/ -function isCmplx128Array( arr ) { - return ( arr instanceof Complex128Array ); -} - - -// MAIN // - -/** -* Creates a typed array pool. -* -* @param {Options} [options] - pool options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} allocator -* -* @example -* var typedarraypool = factory(); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -function factory( options ) { - var nbytes; - var pool; - var opts; - var err; - - opts = defaults(); - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - pool = createPool( ceil( log2( opts.highWaterMark ) ) ); - nbytes = 0; - - setReadOnly( malloc, 'malloc', malloc ); // circular reference - setReadOnly( malloc, 'calloc', calloc ); - setReadOnly( malloc, 'free', free ); - setReadOnly( malloc, 'clear', clear ); - setReadOnly( malloc, 'highWaterMark', opts.highWaterMark ); - setReadOnlyAccessor( malloc, 'nbytes', getBytes ); - - return malloc; - - /** - * Returns the number of allocated bytes. - * - * @private - * @returns {NonNegativeInteger} number of allocated bytes - */ - function getBytes() { - return nbytes; - } - - /** - * Returns an array buffer. - * - * @private - * @param {NonNegativeInteger} n - number of bytes - * @returns {(ArrayBuffer|null)} array buffer or null - */ - function arraybuffer( n ) { - var buf; - var i; - - // Convert the number of bytes to an index in our pool table: - i = log2( n ); - - // If we already have an available array buffer, use it... - if ( i < pool.length && pool[ i ].length ) { - return pool[ i ].pop(); - } - // Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate... - if ( nbytes+n > opts.highWaterMark ) { - return null; - } - buf = new ArrayBuffer( n ); - - // Update the running counter of allocated bytes: - nbytes += n; - - return buf; - } - - /** - * Returns a typed array. - * - * @private - * @param {Function} ctor - typed array constructor - * @param {NonNegativeInteger} len - view length - * @param {string} dtype - data type - * @returns {(TypedArray|null)} typed array or null - */ - function typedarray( ctor, len, dtype ) { - var buf; - if ( len === 0 ) { - return new ctor( 0 ); - } - buf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] ); - if ( buf === null ) { - return buf; - } - return new ctor( buf, 0, len ); - } - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length or an array-like object - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function malloc() { - var nargs; - var dtype; - var ctor; - var arr; - var out; - var set; - var get; - var len; - var i; - - nargs = arguments.length; - if ( nargs && isString( arguments[ nargs-1 ] ) ) { - nargs -= 1; - dtype = arguments[ nargs ]; - } else { - dtype = 'float64'; - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( '01H2Y,KZ', dtype ) ); - } - if ( nargs <= 0 ) { - return new ctor( 0 ); - } - // Check if provided a typed array length... - if ( isNonNegativeInteger( arguments[ 0 ] ) ) { - return typedarray( ctor, arguments[ 0 ], dtype ); - } - // Check if provided an array-like object containing data elements... - if ( isCollection( arguments[ 0 ] ) ) { - arr = arguments[ 0 ]; - len = arr.length; - if ( isComplex128Array( arr ) ) { - arr = reinterpret128( arr, 0 ); - } else if ( isComplex64Array( arr ) ) { - arr = reinterpret64( arr, 0 ); - } else if ( /^complex/.test( dtype ) ) { - // Assume we've been provided an array of interleaved real and imaginary components... - len /= 2; - } - out = typedarray( ctor, len, dtype ); - if ( out === null ) { - return out; - } - if ( isCmplx128Array( out ) || isCmplx64Array( out ) ) { - out.set( arr ); - return out; - } - // Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other "unsafe" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things... - get = accessors( adtype( arr ) ).accessors[ 0 ]; - set = accessors( dtype ).accessors[ 1 ]; - for ( i = 0; i < len; i++ ) { - set( out, i, get( arr, i ) ); - } - return out; - } - throw new TypeError( format( '01H2r,N0', arguments[ 0 ] ) ); - } - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {NonNegativeInteger} [len=0] - array length - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function calloc() { - var nargs; - var out; - var tmp; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - out = malloc(); - } else if ( nargs === 1 ) { - out = malloc( arguments[ 0 ] ); - } else { - out = malloc( arguments[ 0 ], arguments[ 1 ] ); - } - if ( out !== null ) { - // Initialize the memory... - if ( isCmplx128Array( out ) ) { - tmp = reinterpret128( out, 0 ); - } else if ( isCmplx64Array( out ) ) { - tmp = reinterpret64( out, 0 ); - } else { - tmp = out; - } - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = 0.0; - } - } - return out; - } - - /** - * Frees a typed array or typed array buffer. - * - * ## Notes - * - * - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., "freeing" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool. - * - * @private - * @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free - * @throws {TypeError} must provide a typed array or typed array buffer - * @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed - */ - function free( buf ) { - var n; - var p; - var i; - if ( isTypedArrayLike( buf ) && buf.buffer ) { - buf = buf.buffer; - } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( '01H2s,N1', buf ) ); - } - if ( buf.byteLength > 0 ) { - n = floor( log2( buf.byteLength ) ); - - // Prohibit "freeing" array buffers which would potentially allow users to circumvent high water mark limits: - n = min( pool.length-1, n ); - - // Ensure that we do not attempt to free the same buffer more than once... - p = pool[ n ]; - for ( i = 0; i < p.length; i++ ) { - if ( p[ i ] === buf ) { - return false; - } - } - // Add the buffer to our pool of free buffers: - p.push( buf ); - } - return true; - } - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @private - */ - function clear() { - var i; - for ( i = 0; i < pool.length; i++ ) { - pool[ i ].length = 0; - } - nbytes = 0; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6c12a4e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Typed array pool. -* -* @module @stdlib/array-pool -* -* @example -* var typedarraypool = require( '@stdlib/array-pool' ); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8f69ee3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,63 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @name typedarraypool -* @type {Function} -* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a valid array length or an array-like object -* @throws {TypeError} must provide a recognized data type -* @returns {(TypedArray|null)} typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -var typedarraypool = factory(); - - -// EXPORTS // - -module.exports = typedarraypool; diff --git a/lib/pool.js b/lib/pool.js deleted file mode 100644 index 5abd287..0000000 --- a/lib/pool.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Initializes a cache for pooled typed array buffers. -* -* @private -* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size -* @returns {ArrayArray} initialized cache -*/ -function pool( n ) { - var out; - var i; - - out = []; - for ( i = 0; i < n+1; i++ ) { - out.push( [] ); - } - return out; -} - - -// EXPORTS // - -module.exports = pool; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 95667c7..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'highWaterMark': 1024 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '01H2V,FD', options ) ); - } - if ( hasOwnProp( options, 'highWaterMark' ) ) { - opts.highWaterMark = options.highWaterMark; - if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( '01H2t,G9', 'highWaterMark', opts.highWaterMark ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 2110704..bd7b179 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Typed array pool.", "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,76 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessors": "^0.1.0", - "@stdlib/array-buffer": "^0.1.0", - "@stdlib/array-dtype": "^0.1.0", - "@stdlib/array-typed-ctors": "^0.1.0", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-arraybuffer": "^0.1.1", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-complex128array": "^0.1.0", - "@stdlib/assert-is-complex64array": "^0.1.0", - "@stdlib/assert-is-nonnegative-integer": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/assert-is-string": "^0.1.1", - "@stdlib/assert-is-typed-array-like": "^0.1.0", - "@stdlib/math-base-special-ceil": "^0.1.1", - "@stdlib/math-base-special-ceil2": "^0.1.0", - "@stdlib/math-base-special-floor": "^0.1.1", - "@stdlib/math-base-special-log2": "^0.1.1", - "@stdlib/math-base-special-min": "^0.1.1", - "@stdlib/strided-base-reinterpret-complex128": "^0.1.1", - "@stdlib/strided-base-reinterpret-complex64": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.1.0", - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-float32": "^0.1.1", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/array-int16": "^0.1.1", - "@stdlib/array-int32": "^0.1.1", - "@stdlib/array-int8": "^0.1.1", - "@stdlib/array-uint16": "^0.1.1", - "@stdlib/array-uint32": "^0.1.1", - "@stdlib/array-uint8": "^0.1.1", - "@stdlib/array-uint8c": "^0.1.1", - "@stdlib/assert-instance-of": "^0.1.1", - "@stdlib/assert-is-complex-typed-array": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-typed-array": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/complex-float32": "^0.1.1", - "@stdlib/complex-float64": "^0.1.1", - "@stdlib/complex-imag": "^0.1.1", - "@stdlib/complex-imagf": "^0.1.1", - "@stdlib/complex-real": "^0.1.1", - "@stdlib/complex-realf": "^0.1.1", - "@stdlib/math-base-special-pow": "^0.1.0", - "@stdlib/random-base-randu": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..49eaa2a --- /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.factory.js b/test/test.factory.js deleted file mode 100644 index 396aee2..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,2240 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function (no options)', function test( t ) { - t.strictEqual( typeof factory(), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - t.strictEqual( typeof factory( {} ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided a `highWaterMark` option which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (length)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a function which returns a typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, length)', function test( t ) { - var typedarraypool = factory(); - var arr; - - arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a `malloc` method which is a circular reference', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - var buf; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the returned function is a property which returns the pool\'s high water mark', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function supports specifying a high water mark which limits the total amount of memory a pool can allocate', function test( t ) { - var typedarraypool; - var arr1; - var arr2; - - typedarraypool = factory({ - 'highWaterMark': 64 // bytes - }); - - typedarraypool.clear(); - - arr1 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr1.length, 8, 'returns expected value' ); - t.strictEqual( arr1.byteLength, 64, 'returns expected value' ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - typedarraypool.free( arr1 ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Create an array which is less than or equal to the high water mark: - arr2 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr2.length, 8, 'returns expected value' ); - t.strictEqual( arr2.byteLength, 64, 'returns expected value' ); - - typedarraypool.free( arr2 ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a property which returns the total number of accumulated bytes', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var typedarraypool; - var arrs; - var i; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 54aa5ee..0000000 --- a/test/test.js +++ /dev/null @@ -1,1797 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var typedarraypool = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -}); From b844b8a93bf2e8c85dc5b6136608825aa6506807 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 12 Nov 2023 21:28:22 +0000 Subject: [PATCH 049/103] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index edfecbe..ae28056 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -34,7 +34,7 @@ var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); var accessors = require( '@stdlib/array-base-accessors' ); var adtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ArrayBuffer = require( '@stdlib/array-buffer' ); var ceil = require( '@stdlib/math-base-special-ceil' ); var floor = require( '@stdlib/math-base-special-floor' ); @@ -226,7 +226,7 @@ function factory( options ) { } ctor = ctors( dtype ); if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '01H2Y,KZ', dtype ) ); } if ( nargs <= 0 ) { return new ctor( 0 ); @@ -263,7 +263,7 @@ function factory( options ) { } return out; } - throw new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) ); + throw new TypeError( format( '01H2r,N0', arguments[ 0 ] ) ); } /** @@ -329,7 +329,7 @@ function factory( options ) { if ( isTypedArrayLike( buf ) && buf.buffer ) { buf = buf.buffer; } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) ); + throw new TypeError( format( '01H2s,N1', buf ) ); } if ( buf.byteLength > 0 ) { n = floor( log2( buf.byteLength ) ); diff --git a/lib/validate.js b/lib/validate.js index ce54890..95667c7 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '01H2V,FD', options ) ); } if ( hasOwnProp( options, 'highWaterMark' ) ) { opts.highWaterMark = options.highWaterMark; if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) ); + return new TypeError( format( '01H2t,G9', 'highWaterMark', opts.highWaterMark ) ); } } return null; diff --git a/package.json b/package.json index 504e793..6ff9938 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "@stdlib/math-base-special-min": "^0.1.1", "@stdlib/strided-base-reinterpret-complex128": "^0.1.1", "@stdlib/strided-base-reinterpret-complex64": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From fd827bd56cac44ca5566b24c49316ad74bfe60f9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 12 Nov 2023 21:59:52 +0000 Subject: [PATCH 050/103] Remove files --- index.d.ts | 359 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6541 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 c6a3785..0000000 --- a/index.d.ts +++ /dev/null @@ -1,359 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; -import ArrayBuffer = require( '@stdlib/array-buffer' ); - -/** -* Typed array or null. -*/ -type TypedArrayOrNull = RealOrComplexTypedArray | null; - -/** -* Interface defining pool options. -*/ -interface Options { - /** - * Maximum total memory which can be allocated. - */ - highWaterMark?: number; -} - -/** -* Pool interface. -*/ -interface Pool { - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr = typedarraypool(); - * // returns [] - * - * @example - * var arr = typedarraypool( 'float32' ); - * // returns [] - */ - ( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * // Allocate an array of doubles: - * var arr = typedarraypool( 5, 'float64' ); - * // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * typedarraypool.free( arr ); - * - * @example - * var arr1 = typedarraypool( [ 0.5, 0.5, 0.5 ] ); - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * @example - * var arr1 = [ 0.5, 0.5, 0.5 ]; - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - */ - ( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc(); - * // returns [] - * - * var arr2 = typedarraypool.calloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param length - typed array length - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc( 5 ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * var arr2 = typedarraypool.calloc( 5, 'uint8' ); - * // returns [ 0, 0, 0, 0, 0 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( length: number, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc(); - * // returns [] - * - * var arr2 = typedarraypool.malloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc( 5 ); - * // returns - * - * var arr2 = typedarraypool.malloc( 5, 'uint8' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 5.0, -3.0, 2.0 ] ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr2 = typedarraypool.malloc( arr1 ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr3 = typedarraypool.malloc( arr1, 'int32' ); - * // returns [ 5, -3, 2 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * typedarraypool.free( arr3 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ] ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * var arr2 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ], 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Frees a typed array or typed array buffer for use in a future allocation. - * - * @param buf - typed array or typed array buffer to free - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array for use in a future allocation: - * typedarraypool.free( arr ); - * - * // Create another typed array: - * arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array buffer for use in a future allocation: - * typedarraypool.free( arr.buffer ); - */ - free( buf: RealOrComplexTypedArray | ArrayBuffer ): void; - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr ); - * - * // ... - * - * // Clear all freed buffers: - * typedarraypool.clear(); - */ - clear(): void; - - /** - * Read-only property returning the pool's high water mark. - * - * ## Notes - * - * - Once a high water mark is reached, typed array allocation fails. - * - * @example - * var limit = typedarraypool.highWaterMark; - * // returns - */ - readonly highWaterMark: number; - - /** - * Read-only property returning the total number of allocated bytes. - * - * @example - * var arr = typedarraypool( 5, 'float64' ); - * - * var nbytes = typedarraypool.nbytes; - * // returns - */ - readonly nbytes: number; - - /** - * Creates a typed array pool. - * - * @param options - pool options - * @param options.highWaterMark - maximum total memory which can be allocated - * @throws must provide valid options - * @returns allocator - * - * @example - * var allocator = typedarraypool.factory(); - * - * // Allocate an array of doubles: - * var arr = allocator( 5, 'float64' ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * allocator.free( arr ); - */ - factory( options?: Options ): Pool; -} - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @param arg - an array length or an array-like object -* @param dtype - data type (default: 'float64') -* @returns typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -declare var typedarraypool: Pool; - - -// EXPORTS // - -export = typedarraypool; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ceb156c..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessors@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.1.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.1.0-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.1.1-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.1.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";function k(e,t){return y(t)?w(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(c("01H2t,G9","highWaterMark",e.highWaterMark)):null:new TypeError(c("01H2V,FD",t))}function M(e){var t,r;for(t=[],r=0;rH.highWaterMark?null:(t=new j(e),w+=e,t)}function G(e,t,r){var s;return 0===t?new e(0):null===(s=F(u(t)*W[r]))?s:new e(s,0,t)}function K(){var e,i,n,l,j,v,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(n=d(i)))throw new TypeError(c("01H2Y,KZ",i));if(e<=0)return new n(0);if(r(arguments[0]))return G(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,m(l)?l=h(l,0):o(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=G(n,u,i)))return j;if(L(j)||T(j))return j.set(l),j;for(g=p(f(l)).accessors[0],v=p(i).accessors[1],b=0;b0){for(t=g(b(e.byteLength)),t=x(E.length-1,t),r=E[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '01H2Y,KZ', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = accessors( adtype( arr ) ).accessors[ 0 ];\n\t\t\tset = accessors( dtype ).accessors[ 1 ];\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '01H2r,N0', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( '01H2s,N1', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","accessors","adtype","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;ywEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,WAAY,gBAAiBP,EAAKI,gBAG3D,KARC,IAAIE,UAAWC,EAAQ,WAAYN,GAS5C,CC/BA,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,iHCaIG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EC/EO,CACNI,cAAiB,kBD+EbkB,UAAUC,SACdF,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOgB,EAAYC,EAAMC,EAAM1B,EAAKI,iBACpCgB,EAAS,EAETO,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB5B,EAAKI,eAC3C4B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOb,CACP,CASD,SAASc,EAAazB,GACrB,IAAI0B,EACAxB,EAMJ,OAHAA,EAAIe,EAAMjB,IAGDD,EAAKe,QAAUf,EAAMG,GAAIY,OAC1Bf,EAAMG,GAAIyB,MAGbhB,EAAOX,EAAIT,EAAKI,cACb,MAER+B,EAAM,IAAIE,EAAa5B,GAGvBW,GAAUX,EAEH0B,EACP,CAWD,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,EACzB,CAkBD,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAtB,EACAP,EACAmC,EACAC,EACAN,EACA7B,EAUJ,GALC8B,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAOzB,EAAO2B,IAEb,MAAM,IAAInC,UAAWC,EAAQ,WAAYkC,IAE1C,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKlC,EAAsBiB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAvB,EAAMK,UAAW,IACPC,OACL0B,EAAmBhC,GACvBA,EAAMiC,EAAgBjC,EAAK,GAChBkC,EAAkBlC,GAC7BA,EAAMmC,EAAenC,EAAK,GACf,WAAWoC,KAAMZ,KAE5BD,GAAO,GAGK,QADb9B,EAAM4B,EAAYC,EAAMC,EAAKC,IAE5B,OAAO/B,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAImC,IAAK5B,GACFP,EAKR,IAFAoC,EAAMQ,EAAWC,EAAQtC,IAAQqC,UAAW,GAC5CT,EAAMS,EAAWb,GAAQa,UAAW,GAC9B3C,EAAI,EAAGA,EAAI6B,EAAK7B,IACrBkC,EAAKnC,EAAKC,EAAGmC,EAAK7B,EAAKN,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,WAAYe,UAAW,IACpD,CAgBD,SAASO,IACR,IAAIe,EACAlC,EACA8C,EACA7C,EAUJ,GAAa,QANZD,EADc,KADfkC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCkC,EADItC,EAAiBR,GACfwC,EAAgBxC,EAAK,GAChBM,EAAgBN,GACrB0C,EAAe1C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAI6C,EAAIjC,OAAQZ,IAC5B6C,EAAK7C,GAAM,EAGb,OAAOD,CACP,CAcD,SAASoB,EAAMK,GACd,IAAI1B,EACAgD,EACA9C,EACJ,GAAK+C,EAAkBvB,IAASA,EAAIwB,OACnCxB,EAAMA,EAAIwB,YACJ,IAAMC,EAAezB,GAC3B,MAAM,IAAI7B,UAAWC,EAAQ,WAAY4B,IAE1C,GAAKA,EAAI0B,WAAa,EAAI,CAQzB,IAPApD,EAAIqD,EAAOpC,EAAMS,EAAI0B,aAGrBpD,EAAIsD,EAAKvD,EAAKe,OAAO,EAAGd,GAGxBgD,EAAIjD,EAAMC,GACJE,EAAI,EAAGA,EAAI8C,EAAElC,OAAQZ,IAC1B,GAAK8C,EAAG9C,KAAQwB,EACf,OAAO,EAITsB,EAAE7C,KAAMuB,EACR,CACD,OAAO,CACP,CAOD,SAASJ,IACR,IAAIpB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKe,OAAQZ,IAC7BH,EAAMG,GAAIY,OAAS,EAEpBH,EAAS,CACT,CACF,CEnTG,IAAC4C,EAAiB7C,ICPrBQ,EAAAsC,EAAA,UAAA9C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 49eaa2a..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 41d7e8f23c2e8ce4142a9ace717481061ed031be Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 12 Nov 2023 22:03:36 +0000 Subject: [PATCH 051/103] 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 | 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 | 43 +- benchmark/benchmark.calloc.js | 246 - benchmark/benchmark.factory.js | 71 - benchmark/benchmark.js | 246 - benchmark/benchmark.length.complex128.js | 102 - benchmark/benchmark.length.complex64.js | 102 - benchmark/benchmark.length.float32.js | 102 - benchmark/benchmark.length.float64.js | 102 - benchmark/benchmark.length.int16.js | 102 - benchmark/benchmark.length.int32.js | 102 - benchmark/benchmark.length.int8.js | 102 - benchmark/benchmark.length.uint16.js | 102 - benchmark/benchmark.length.uint32.js | 102 - benchmark/benchmark.length.uint8.js | 102 - benchmark/benchmark.length.uint8c.js | 102 - benchmark/benchmark.malloc.js | 246 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 347 -- docs/types/test.ts | 193 - examples/index.js | 80 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/bytes_per_element.json | 13 - lib/defaults.js | 42 - lib/factory.js | 370 -- lib/index.js | 56 - lib/main.js | 63 - lib/pool.js | 44 - lib/validate.js | 66 - package.json | 97 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 2240 -------- test/test.js | 1797 ------ 61 files changed, 6206 insertions(+), 10637 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.calloc.js delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.complex128.js delete mode 100644 benchmark/benchmark.length.complex64.js delete mode 100644 benchmark/benchmark.length.float32.js delete mode 100644 benchmark/benchmark.length.float64.js delete mode 100644 benchmark/benchmark.length.int16.js delete mode 100644 benchmark/benchmark.length.int32.js delete mode 100644 benchmark/benchmark.length.int8.js delete mode 100644 benchmark/benchmark.length.uint16.js delete mode 100644 benchmark/benchmark.length.uint32.js delete mode 100644 benchmark/benchmark.length.uint8.js delete mode 100644 benchmark/benchmark.length.uint8c.js delete mode 100644 benchmark/benchmark.malloc.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/bytes_per_element.json delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/pool.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ea35f20..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/array/pool) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6f7c875..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/array/pool) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 4f5a65c..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -493,7 +492,7 @@ console.log( 'nbytes: %d', typedarray.nbytes ); ## 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]. @@ -559,7 +558,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm diff --git a/benchmark/benchmark.calloc.js b/benchmark/benchmark.calloc.js deleted file mode 100644 index e5a1c77..0000000 --- a/benchmark/benchmark.calloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':calloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index f7cd676..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = typedarray.factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:highWaterMark', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'highWaterMark': 0 - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.highWaterMark = i; - f = typedarray.factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a023d2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.complex128.js b/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 47b623b..0000000 --- a/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex64.js b/benchmark/benchmark.length.complex64.js deleted file mode 100644 index 40a412b..0000000 --- a/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float32.js b/benchmark/benchmark.length.float32.js deleted file mode 100644 index 0227ed7..0000000 --- a/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float64.js b/benchmark/benchmark.length.float64.js deleted file mode 100644 index 2dbac1c..0000000 --- a/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int16.js b/benchmark/benchmark.length.int16.js deleted file mode 100644 index e2a8adc..0000000 --- a/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int32.js b/benchmark/benchmark.length.int32.js deleted file mode 100644 index e4df0aa..0000000 --- a/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int8.js b/benchmark/benchmark.length.int8.js deleted file mode 100644 index 7ceac11..0000000 --- a/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint16.js b/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 9a532b6..0000000 --- a/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint32.js b/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 98f2d7f..0000000 --- a/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8.js b/benchmark/benchmark.length.uint8.js deleted file mode 100644 index 8359249..0000000 --- a/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8c.js b/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index d47d023..0000000 --- a/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.malloc.js b/benchmark/benchmark.malloc.js deleted file mode 100644 index d4eea72..0000000 --- a/benchmark/benchmark.malloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':malloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 9689761..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/array/pool" -%% click B href "https://github.com/stdlib-js/array-pool/tree/main" -%% click C href "https://github.com/stdlib-js/array-pool/tree/production" -%% click D href "https://github.com/stdlib-js/array-pool/tree/esm" -%% click E href "https://github.com/stdlib-js/array-pool/tree/deno" -%% click F href "https://github.com/stdlib-js/array-pool/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/pool -[production-url]: https://github.com/stdlib-js/array-pool/tree/production -[deno-url]: https://github.com/stdlib-js/array-pool/tree/deno -[umd-url]: https://github.com/stdlib-js/array-pool/tree/umd -[esm-url]: https://github.com/stdlib-js/array-pool/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 5160b6f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import typedarraypool from '../docs/types/index'; -export = typedarraypool; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 9d31d69..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var l=function(n,i){return function(){return i||n((i={exports:{}}).exports,i),i.exports}};var k=l(function(kr,M){ -function D(){return{highWaterMark:9007199254740992}}M.exports=D -});var E=l(function(Ar,W){ -var G=require('@stdlib/assert-is-plain-object/dist'),H=require('@stdlib/assert-has-own-property/dist'),J=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,A=require('@stdlib/error-tools-fmtprodmsg/dist');function K(n,i){return G(i)?H(i,"highWaterMark")&&(n.highWaterMark=i.highWaterMark,!J(n.highWaterMark))?new TypeError(A('01H2t',"highWaterMark",n.highWaterMark)):null:new TypeError(A('01H2V',i));}W.exports=K -});var C=l(function(Wr,T){ -function Q(n){var i,u;for(i=[],u=0;uv.highWaterMark?null:(e=new ur(r),i+=r,e)}function d(r,e,t){var a;return e===0?new r(0):(a=_(lr(e)*hr[t]),a===null?a:new r(a,0,e))}function s(){var r,e,t,a,o,x,w,c,f;if(r=arguments.length,r&&X(arguments[r-1])?(r-=1,e=arguments[r]):e="float64",t=y(e),t===null)throw new TypeError(m('01H2Y',e));if(r<=0)return new t(0);if(Z(arguments[0]))return d(t,arguments[0],e);if($(arguments[0])){if(a=arguments[0],c=a.length,tr(a)?a=P(a,0):ar(a)?a=b(a,0):/^complex/.test(e)&&(c/=2),o=d(t,c,e),o===null)return o;if(L(o)||N(o))return o.set(a),o;for(w=B(nr(a)).accessors[0],x=B(e).accessors[1],f=0;f0){for(e=or(p(r.byteLength)),e=vr(u.length-1,e),t=u[e],a=0;a[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = accessors( adtype( arr ) ).accessors[ 0 ];\n\t\t\tset = accessors( dtype ).accessors[ 1 ];\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nmodule.exports = typedarraypool;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* var typedarraypool = require( '@stdlib/array-pool' );\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,cAAiB,gBAClB,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,eAAgB,IACzCD,EAAK,cAAgBC,EAAQ,cACxB,CAACJ,EAAsBG,EAAK,aAAc,GACvC,IAAI,UAAWF,EAAQ,2EAA4E,gBAAiBE,EAAK,aAAc,CAAE,EAG3I,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cA6BA,SAASC,EAAM,EAAI,CAClB,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAI,EAAE,EAAGA,IACrBD,EAAI,KAAM,CAAC,CAAE,EAEd,OAAOA,CACR,CAKAF,EAAO,QAAUC,IC3CjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,QAAW,EACX,QAAW,EACX,MAAS,EACT,MAAS,EACT,KAAQ,EACR,OAAU,EACV,OAAU,EACV,MAAS,EACT,OAAU,EACT,UAAa,EACb,WAAc,EAChB,ICZA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAe,QAAS,8BAA+B,EACvDC,GAAmB,QAAS,oCAAqC,EACjEC,GAAgB,QAAS,+BAAgC,EACzDC,GAAmB,QAAS,kCAAmC,EAC/DC,GAAoB,QAAS,mCAAoC,EACjEC,EAAc,QAAS,uDAAwD,EAC/EC,GAAsB,QAAS,uDAAwD,EACvFC,EAAQ,QAAS,2BAA4B,EAC7CC,EAAgB,QAAS,4CAA6C,EACtEC,EAAiB,QAAS,6CAA8C,EACxEC,EAAY,QAAS,8BAA+B,EACpDC,GAAS,QAAS,qBAAsB,EACxCC,EAAS,QAAS,uBAAwB,EAC1CC,GAAc,QAAS,sBAAuB,EAC9CC,GAAO,QAAS,gCAAiC,EACjDC,GAAQ,QAAS,iCAAkC,EACnDC,GAAQ,QAAS,iCAAkC,EACnDC,EAAO,QAAS,gCAAiC,EACjDC,GAAM,QAAS,+BAAgC,EAC/CC,GAAW,IACXC,GAAW,IACXC,GAAa,IACbC,GAAoB,IAKpBC,GAAiBhB,EAAO,WAAY,EACpCiB,GAAkBjB,EAAO,YAAa,EAY1C,SAASkB,EAAgBC,EAAM,CAC9B,OAASA,aAAeH,EACzB,CASA,SAASI,EAAiBD,EAAM,CAC/B,OAASA,aAAeF,EACzB,CA6BA,SAASI,GAASC,EAAU,CAC3B,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,EAAOb,GAAS,EACX,UAAU,SACdc,EAAMb,GAAUY,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAAF,EAAOV,GAAYP,GAAMG,EAAMe,EAAK,aAAc,CAAE,CAAE,EACtDF,EAAS,EAETzB,EAAa6B,EAAQ,SAAUA,CAAO,EACtC7B,EAAa6B,EAAQ,SAAUC,CAAO,EACtC9B,EAAa6B,EAAQ,OAAQE,CAAK,EAClC/B,EAAa6B,EAAQ,QAASG,CAAM,EACpChC,EAAa6B,EAAQ,gBAAiBF,EAAK,aAAc,EACzD1B,GAAqB4B,EAAQ,SAAUI,CAAS,EAEzCJ,EAQP,SAASI,GAAW,CACnB,OAAOR,CACR,CASA,SAASS,EAAaC,EAAI,CACzB,IAAIC,EACAC,EAMJ,OAHAA,EAAIzB,EAAMuB,CAAE,EAGPE,EAAIX,EAAK,QAAUA,EAAMW,CAAE,EAAE,OAC1BX,EAAMW,CAAE,EAAE,IAAI,EAGjBZ,EAAOU,EAAIR,EAAK,cACb,MAERS,EAAM,IAAI5B,GAAa2B,CAAE,EAGzBV,GAAUU,EAEHC,EACR,CAWA,SAASE,EAAYC,EAAMC,EAAKC,EAAQ,CACvC,IAAIL,EACJ,OAAKI,IAAQ,EACL,IAAID,EAAM,CAAE,GAEpBH,EAAMF,EAAavB,GAAO6B,CAAI,EAAEvB,GAAmBwB,CAAM,CAAE,EACtDL,IAAQ,KACLA,EAED,IAAIG,EAAMH,EAAK,EAAGI,CAAI,EAC9B,CAkBA,SAASX,GAAS,CACjB,IAAIa,EACAD,EACAF,EACAlB,EACAsB,EACAC,EACAC,EACAL,EACAH,EAUJ,GARAK,EAAQ,UAAU,OACbA,GAASjD,EAAU,UAAWiD,EAAM,CAAE,CAAE,GAC5CA,GAAS,EACTD,EAAQ,UAAWC,CAAM,GAEzBD,EAAQ,UAETF,EAAOrC,EAAOuC,CAAM,EACfF,IAAS,KACb,MAAM,IAAI,UAAWhC,EAAQ,sEAAuEkC,CAAM,CAAE,EAE7G,GAAKC,GAAS,EACb,OAAO,IAAIH,EAAM,CAAE,EAGpB,GAAK7C,EAAsB,UAAW,CAAE,CAAE,EACzC,OAAO4C,EAAYC,EAAM,UAAW,CAAE,EAAGE,CAAM,EAGhD,GAAK9C,EAAc,UAAW,CAAE,CAAE,EAAI,CAYrC,GAXA0B,EAAM,UAAW,CAAE,EACnBmB,EAAMnB,EAAI,OACLtB,GAAmBsB,CAAI,EAC3BA,EAAMjB,EAAgBiB,EAAK,CAAE,EAClBvB,GAAkBuB,CAAI,EACjCA,EAAMlB,EAAekB,EAAK,CAAE,EACjB,WAAW,KAAMoB,CAAM,IAElCD,GAAO,GAERG,EAAML,EAAYC,EAAMC,EAAKC,CAAM,EAC9BE,IAAQ,KACZ,OAAOA,EAER,GAAKrB,EAAiBqB,CAAI,GAAKvB,EAAgBuB,CAAI,EAClD,OAAAA,EAAI,IAAKtB,CAAI,EACNsB,EAKR,IAFAE,EAAMxC,EAAWC,GAAQe,CAAI,CAAE,EAAE,UAAW,CAAE,EAC9CuB,EAAMvC,EAAWoC,CAAM,EAAE,UAAW,CAAE,EAChCJ,EAAI,EAAGA,EAAIG,EAAKH,IACrBO,EAAKD,EAAKN,EAAGQ,EAAKxB,EAAKgB,CAAE,CAAE,EAE5B,OAAOM,CACR,CACA,MAAM,IAAI,UAAWpC,EAAQ,wGAAyG,UAAW,CAAE,CAAE,CAAE,CACxJ,CAgBA,SAASuB,GAAS,CACjB,IAAIY,EACAC,EACAG,EACAT,EAUJ,GARAK,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAMd,EAAO,EACFa,IAAU,EACrBC,EAAMd,EAAQ,UAAW,CAAE,CAAE,EAE7Bc,EAAMd,EAAQ,UAAW,CAAE,EAAG,UAAW,CAAE,CAAE,EAEzCc,IAAQ,KASZ,IAPKrB,EAAiBqB,CAAI,EACzBG,EAAM1C,EAAgBuC,EAAK,CAAE,EAClBvB,EAAgBuB,CAAI,EAC/BG,EAAM3C,EAAewC,EAAK,CAAE,EAE5BG,EAAMH,EAEDN,EAAI,EAAGA,EAAIS,EAAI,OAAQT,IAC5BS,EAAKT,CAAE,EAAI,EAGb,OAAOM,CACR,CAcA,SAASZ,EAAMK,EAAM,CACpB,IAAID,EACAY,EACAV,EACJ,GAAKzC,GAAkBwC,CAAI,GAAKA,EAAI,OACnCA,EAAMA,EAAI,eACC,CAACvC,GAAeuC,CAAI,EAC/B,MAAM,IAAI,UAAW7B,EAAQ,4EAA6E6B,CAAI,CAAE,EAEjH,GAAKA,EAAI,WAAa,EAAI,CAQzB,IAPAD,EAAIzB,GAAOE,EAAMwB,EAAI,UAAW,CAAE,EAGlCD,EAAItB,GAAKa,EAAK,OAAO,EAAGS,CAAE,EAG1BY,EAAIrB,EAAMS,CAAE,EACNE,EAAI,EAAGA,EAAIU,EAAE,OAAQV,IAC1B,GAAKU,EAAGV,CAAE,IAAMD,EACf,MAAO,GAITW,EAAE,KAAMX,CAAI,CACb,CACA,MAAO,EACR,CAOA,SAASJ,GAAQ,CAChB,IAAIK,EACJ,IAAMA,EAAI,EAAGA,EAAIX,EAAK,OAAQW,IAC7BX,EAAMW,CAAE,EAAE,OAAS,EAEpBZ,EAAS,CACV,CACD,CAKAjC,EAAO,QAAU+B,KCjXjB,IAAAyB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAU,IAmCVC,GAAiBD,GAAQ,EAK7BD,EAAO,QAAUE,KCnBjB,IAAIC,GAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,GAAU,IAKdF,GAAaC,EAAM,UAAWC,EAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isNonNegativeInteger", "format", "validate", "opts", "options", "require_pool", "__commonJSMin", "exports", "module", "pool", "out", "i", "require_bytes_per_element", "__commonJSMin", "exports", "module", "require_factory", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isCollection", "isTypedArrayLike", "isArrayBuffer", "isComplex64Array", "isComplex128Array", "setReadOnly", "setReadOnlyAccessor", "ctors", "reinterpret64", "reinterpret128", "accessors", "adtype", "format", "ArrayBuffer", "ceil", "floor", "ceil2", "log2", "min", "defaults", "validate", "createPool", "BYTES_PER_ELEMENT", "Complex64Array", "Complex128Array", "isCmplx64Array", "arr", "isCmplx128Array", "factory", "options", "nbytes", "pool", "opts", "err", "malloc", "calloc", "free", "clear", "getBytes", "arraybuffer", "n", "buf", "i", "typedarray", "ctor", "len", "dtype", "nargs", "out", "set", "get", "tmp", "p", "require_main", "__commonJSMin", "exports", "module", "factory", "typedarraypool", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5244595..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,347 +0,0 @@ - -{{alias}}( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - Memory is **uninitialized**, which means that the contents of a returned - typed array may contain sensitive contents. - - The function supports the following data types: - - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - The default typed array data type is `float64`. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}() - [] - > arr = {{alias}}( 'float32' ) - [] - - -{{alias}}( length[, dtype] ) - Returns an uninitialized typed array having a specified length from a typed - array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > arr = {{alias}}( 5, 'int32' ) - - - -{{alias}}( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - This method shares the same security vulnerabilities mentioned above. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc() - - > arr = {{alias}}.malloc( 'float32' ) - - - -{{alias}}.malloc( length[, dtype] ) - Returns a typed array having a specified length from a typed array memory - pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc( 5 ) - - > arr = {{alias}}.malloc( 5, 'int32' ) - - - -{{alias}}.malloc( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}.malloc( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.calloc( [dtype] ) - Returns a zero-initialized typed array from a typed array memory pool. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc() - [] - > arr = {{alias}}.calloc( 'float32' ) - [] - - -{{alias}}.calloc( length[, dtype] ) - Returns a zero-initialized typed array having a specified length from a - typed array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}.calloc( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}.free( buf ) - Frees a typed array or typed array buffer for use in a future allocation. - - Parameters - ---------- - buf: TypedArray|ArrayBuffer - Typed array or typed array buffer to free. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ) - - -{{alias}}.clear() - Clears the typed array pool allowing garbage collection of previously - allocated (and currently free) array buffers. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - > {{alias}}.clear() - - -{{alias}}.highWaterMark - Read-only property returning the pool's high water mark. - - Once a high water mark is reached, typed array allocation fails. - - Examples - -------- - > {{alias}}.highWaterMark - - -{{alias}}.nbytes - Read-only property returning the total number of allocated bytes. - - The returned value is the total accumulated value. Hence, anytime a pool - must allocate a new array buffer (i.e., more memory), the pool increments - this value. - - The only time this value is decremented is when a pool is cleared. - - This behavior means that, while allocated buffers which are never freed may, - in fact, be garbage collected, they continue to count against the high water - mark limit. - - Accordingly, you should *always* free allocated buffers in order to prevent - the pool from believing that non-freed buffers are continually in use. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.nbytes - - -{{alias}}.factory( [options] ) - Creates a typed array pool. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.highWaterMark: integer (optional) - Maximum total memory (in bytes) which can be allocated. - - Returns - ------- - fcn: Function - Function for creating typed arrays from a typed array memory pool. - - Examples - -------- - > var pool = {{alias}}.factory(); - > var arr1 = pool( 3, 'float64' ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 4336c42..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,193 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-empty */ -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import typedarraypool = require( './index' ); - - -// TESTS // - -// The function returns a typed array or null... -{ - typedarraypool(); // $ExpectType TypedArrayOrNull - typedarraypool( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the function is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool( true ); // $ExpectError - typedarraypool( false ); // $ExpectError - typedarraypool( null ); // $ExpectError - typedarraypool( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized data type... -{ - typedarraypool( 4, true ); // $ExpectError - typedarraypool( 4, false ); // $ExpectError - typedarraypool( 4, null ); // $ExpectError - typedarraypool( 4, 'abc' ); // $ExpectError - typedarraypool( 4, 123 ); // $ExpectError - typedarraypool( 4, [] ); // $ExpectError - typedarraypool( 4, {} ); // $ExpectError - typedarraypool( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an incorrect number of arguments... -{ - typedarraypool( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `malloc` method which returns a typed array or null... -{ - typedarraypool.malloc(); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.malloc( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `malloc` method is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool.malloc( true ); // $ExpectError - typedarraypool.malloc( false ); // $ExpectError - typedarraypool.malloc( null ); // $ExpectError - typedarraypool.malloc( {} ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.malloc( 4, true ); // $ExpectError - typedarraypool.malloc( 4, false ); // $ExpectError - typedarraypool.malloc( 4, null ); // $ExpectError - typedarraypool.malloc( 4, 'abc' ); // $ExpectError - typedarraypool.malloc( 4, 123 ); // $ExpectError - typedarraypool.malloc( 4, [] ); // $ExpectError - typedarraypool.malloc( 4, {} ); // $ExpectError - typedarraypool.malloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided an incorrect number of arguments... -{ - typedarraypool.malloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `calloc` method which returns a typed array or null... -{ - typedarraypool.calloc(); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `calloc` method is provided a first argument which is not a number... -{ - typedarraypool.calloc( 'abc' ); // $ExpectError - typedarraypool.calloc( true ); // $ExpectError - typedarraypool.calloc( false ); // $ExpectError - typedarraypool.calloc( null ); // $ExpectError - typedarraypool.calloc( {} ); // $ExpectError - typedarraypool.calloc( [] ); // $ExpectError - typedarraypool.calloc( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.calloc( 4, true ); // $ExpectError - typedarraypool.calloc( 4, false ); // $ExpectError - typedarraypool.calloc( 4, null ); // $ExpectError - typedarraypool.calloc( 4, 'abc' ); // $ExpectError - typedarraypool.calloc( 4, 123 ); // $ExpectError - typedarraypool.calloc( 4, [] ); // $ExpectError - typedarraypool.calloc( 4, {} ); // $ExpectError - typedarraypool.calloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided an incorrect number of arguments... -{ - typedarraypool.calloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `factory` method which returns a typed array pool.. -{ - typedarraypool.factory(); // $ExpectType Pool - typedarraypool.factory( { 'highWaterMark': 556 } ); // $ExpectType Pool -} - -// The compiler throws an error if the `factory` method is provided a `highWaterMark` option which is not a number... -{ - typedarraypool.factory( { 'highWaterMark': true } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': false } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': 'abc' } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': null } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': [] } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': {} } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an incorrect number of arguments... -{ - typedarraypool.factory( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` method which returns void... -{ - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.free( arr ); // $ExpectType void -} - -// The compiler throws an error if the `free` method is provided a first argument which is neither a typed array nor array buffer... -{ - typedarraypool.free( true ); // $ExpectError - typedarraypool.free( false ); // $ExpectError - typedarraypool.free( 123 ); // $ExpectError - typedarraypool.free( 'abc' ); // $ExpectError - typedarraypool.free( null ); // $ExpectError - typedarraypool.free( {} ); // $ExpectError - typedarraypool.free( ( x: number ): number => x ); // $ExpectError -} - -// Attached to the main export is a `clear` method which returns void... -{ - typedarraypool.clear(); // $ExpectType void -} - -// The compiler throws an error if the `clear` method is provided arguments... -{ - typedarraypool.clear( {} ); // $ExpectError - typedarraypool.clear( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `highWaterMark` property... -{ - typedarraypool.highWaterMark; // $ExpectType number -} - -// Attached to the main export is a `nbytes` property... -{ - typedarraypool.nbytes; // $ExpectType number -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 24a7846..0000000 --- a/examples/index.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 randu = require( '@stdlib/random-base-randu' ); -var typedarraypool = require( './../lib' ); - -// Create a typed array pool which can allocate at most 1GB: -var typedarray = typedarraypool.factory({ - 'highWaterMark': 1e9 -}); - -// Inspect the pool: -console.log( 'Max bytes: %d', typedarray.highWaterMark ); -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Allocate an array for storing double-precision floating-point numbers: -var arr1 = typedarray( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Fill the array... -var i; -for ( i = 0; i < arr1.length; i++ ) { - arr1[ i ] = randu(); -} - -// Inspect array contents: -console.log( arr1 ); - -// Free the array: -typedarray.free( arr1 ); - -// Allocate another array similar to the previous one: -var arr2 = typedarray( 5, 'float64' ); -// returns - -// Check that we have been returned a new typed array view: -console.log( arr2 === arr1 ); -// => false - -// Inspect array contents: -console.log( arr2 ); - -// Free the array: -typedarray.free( arr2 ); - -// Allocate an initialized array: -var arr3 = typedarray.calloc( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect array contents: -console.log( arr3 ); - -// Free the array: -typedarray.free( arr3 ); - -// Clear the pool: -typedarray.clear(); - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index de70cb0..c6a3785 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; import ArrayBuffer = require( '@stdlib/array-buffer' ); diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ceb156c --- /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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessors@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.1.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.1.0-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.1.1-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.1.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";function k(e,t){return y(t)?w(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(c("01H2t,G9","highWaterMark",e.highWaterMark)):null:new TypeError(c("01H2V,FD",t))}function M(e){var t,r;for(t=[],r=0;rH.highWaterMark?null:(t=new j(e),w+=e,t)}function G(e,t,r){var s;return 0===t?new e(0):null===(s=F(u(t)*W[r]))?s:new e(s,0,t)}function K(){var e,i,n,l,j,v,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(n=d(i)))throw new TypeError(c("01H2Y,KZ",i));if(e<=0)return new n(0);if(r(arguments[0]))return G(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,m(l)?l=h(l,0):o(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=G(n,u,i)))return j;if(L(j)||T(j))return j.set(l),j;for(g=p(f(l)).accessors[0],v=p(i).accessors[1],b=0;b0){for(t=g(b(e.byteLength)),t=x(E.length-1,t),r=E[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '01H2Y,KZ', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = accessors( adtype( arr ) ).accessors[ 0 ];\n\t\t\tset = accessors( dtype ).accessors[ 1 ];\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '01H2r,N0', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( '01H2s,N1', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","accessors","adtype","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;ywEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,WAAY,gBAAiBP,EAAKI,gBAG3D,KARC,IAAIE,UAAWC,EAAQ,WAAYN,GAS5C,CC/BA,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,iHCaIG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EC/EO,CACNI,cAAiB,kBD+EbkB,UAAUC,SACdF,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOgB,EAAYC,EAAMC,EAAM1B,EAAKI,iBACpCgB,EAAS,EAETO,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB5B,EAAKI,eAC3C4B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOb,CACP,CASD,SAASc,EAAazB,GACrB,IAAI0B,EACAxB,EAMJ,OAHAA,EAAIe,EAAMjB,IAGDD,EAAKe,QAAUf,EAAMG,GAAIY,OAC1Bf,EAAMG,GAAIyB,MAGbhB,EAAOX,EAAIT,EAAKI,cACb,MAER+B,EAAM,IAAIE,EAAa5B,GAGvBW,GAAUX,EAEH0B,EACP,CAWD,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,EACzB,CAkBD,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAtB,EACAP,EACAmC,EACAC,EACAN,EACA7B,EAUJ,GALC8B,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAOzB,EAAO2B,IAEb,MAAM,IAAInC,UAAWC,EAAQ,WAAYkC,IAE1C,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKlC,EAAsBiB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAvB,EAAMK,UAAW,IACPC,OACL0B,EAAmBhC,GACvBA,EAAMiC,EAAgBjC,EAAK,GAChBkC,EAAkBlC,GAC7BA,EAAMmC,EAAenC,EAAK,GACf,WAAWoC,KAAMZ,KAE5BD,GAAO,GAGK,QADb9B,EAAM4B,EAAYC,EAAMC,EAAKC,IAE5B,OAAO/B,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAImC,IAAK5B,GACFP,EAKR,IAFAoC,EAAMQ,EAAWC,EAAQtC,IAAQqC,UAAW,GAC5CT,EAAMS,EAAWb,GAAQa,UAAW,GAC9B3C,EAAI,EAAGA,EAAI6B,EAAK7B,IACrBkC,EAAKnC,EAAKC,EAAGmC,EAAK7B,EAAKN,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,WAAYe,UAAW,IACpD,CAgBD,SAASO,IACR,IAAIe,EACAlC,EACA8C,EACA7C,EAUJ,GAAa,QANZD,EADc,KADfkC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCkC,EADItC,EAAiBR,GACfwC,EAAgBxC,EAAK,GAChBM,EAAgBN,GACrB0C,EAAe1C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAI6C,EAAIjC,OAAQZ,IAC5B6C,EAAK7C,GAAM,EAGb,OAAOD,CACP,CAcD,SAASoB,EAAMK,GACd,IAAI1B,EACAgD,EACA9C,EACJ,GAAK+C,EAAkBvB,IAASA,EAAIwB,OACnCxB,EAAMA,EAAIwB,YACJ,IAAMC,EAAezB,GAC3B,MAAM,IAAI7B,UAAWC,EAAQ,WAAY4B,IAE1C,GAAKA,EAAI0B,WAAa,EAAI,CAQzB,IAPApD,EAAIqD,EAAOpC,EAAMS,EAAI0B,aAGrBpD,EAAIsD,EAAKvD,EAAKe,OAAO,EAAGd,GAGxBgD,EAAIjD,EAAMC,GACJE,EAAI,EAAGA,EAAI8C,EAAElC,OAAQZ,IAC1B,GAAK8C,EAAG9C,KAAQwB,EACf,OAAO,EAITsB,EAAE7C,KAAMuB,EACR,CACD,OAAO,CACP,CAOD,SAASJ,IACR,IAAIpB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKe,OAAQZ,IAC7BH,EAAMG,GAAIY,OAAS,EAEpBH,EAAS,CACT,CACF,CEnTG,IAAC4C,EAAiB7C,ICPrBQ,EAAAsC,EAAA,UAAA9C"} \ No newline at end of file diff --git a/lib/bytes_per_element.json b/lib/bytes_per_element.json deleted file mode 100644 index f97fe70..0000000 --- a/lib/bytes_per_element.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "float64": 8, - "float32": 4, - "int16": 2, - "int32": 4, - "int8": 1, - "uint16": 2, - "uint32": 4, - "uint8": 1, - "uint8c": 1, - "complex64": 8, - "complex128": 16 -} diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index a421711..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +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'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'highWaterMark': 9007199254740992 - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index ae28056..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,370 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var isComplex64Array = require( '@stdlib/assert-is-complex64array' ); -var isComplex128Array = require( '@stdlib/assert-is-complex128array' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var ctors = require( '@stdlib/array-typed-ctors' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var accessors = require( '@stdlib/array-base-accessors' ); -var adtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil = require( '@stdlib/math-base-special-ceil' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); -var log2 = require( '@stdlib/math-base-special-log2' ); -var min = require( '@stdlib/math-base-special-min' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var createPool = require( './pool.js' ); -var BYTES_PER_ELEMENT = require( './bytes_per_element.json' ); - - -// VARIABLES // - -var Complex64Array = ctors( 'complex64' ); -var Complex128Array = ctors( 'complex128' ); - - -// FUNCTIONS // - -/** -* Tests whether an array is a single-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a single-precision complex floating-point number array -*/ -function isCmplx64Array( arr ) { - return ( arr instanceof Complex64Array ); -} - -/** -* Tests whether an array is a double-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a double-precision complex floating-point number array -*/ -function isCmplx128Array( arr ) { - return ( arr instanceof Complex128Array ); -} - - -// MAIN // - -/** -* Creates a typed array pool. -* -* @param {Options} [options] - pool options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} allocator -* -* @example -* var typedarraypool = factory(); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -function factory( options ) { - var nbytes; - var pool; - var opts; - var err; - - opts = defaults(); - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - pool = createPool( ceil( log2( opts.highWaterMark ) ) ); - nbytes = 0; - - setReadOnly( malloc, 'malloc', malloc ); // circular reference - setReadOnly( malloc, 'calloc', calloc ); - setReadOnly( malloc, 'free', free ); - setReadOnly( malloc, 'clear', clear ); - setReadOnly( malloc, 'highWaterMark', opts.highWaterMark ); - setReadOnlyAccessor( malloc, 'nbytes', getBytes ); - - return malloc; - - /** - * Returns the number of allocated bytes. - * - * @private - * @returns {NonNegativeInteger} number of allocated bytes - */ - function getBytes() { - return nbytes; - } - - /** - * Returns an array buffer. - * - * @private - * @param {NonNegativeInteger} n - number of bytes - * @returns {(ArrayBuffer|null)} array buffer or null - */ - function arraybuffer( n ) { - var buf; - var i; - - // Convert the number of bytes to an index in our pool table: - i = log2( n ); - - // If we already have an available array buffer, use it... - if ( i < pool.length && pool[ i ].length ) { - return pool[ i ].pop(); - } - // Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate... - if ( nbytes+n > opts.highWaterMark ) { - return null; - } - buf = new ArrayBuffer( n ); - - // Update the running counter of allocated bytes: - nbytes += n; - - return buf; - } - - /** - * Returns a typed array. - * - * @private - * @param {Function} ctor - typed array constructor - * @param {NonNegativeInteger} len - view length - * @param {string} dtype - data type - * @returns {(TypedArray|null)} typed array or null - */ - function typedarray( ctor, len, dtype ) { - var buf; - if ( len === 0 ) { - return new ctor( 0 ); - } - buf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] ); - if ( buf === null ) { - return buf; - } - return new ctor( buf, 0, len ); - } - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length or an array-like object - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function malloc() { - var nargs; - var dtype; - var ctor; - var arr; - var out; - var set; - var get; - var len; - var i; - - nargs = arguments.length; - if ( nargs && isString( arguments[ nargs-1 ] ) ) { - nargs -= 1; - dtype = arguments[ nargs ]; - } else { - dtype = 'float64'; - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( '01H2Y,KZ', dtype ) ); - } - if ( nargs <= 0 ) { - return new ctor( 0 ); - } - // Check if provided a typed array length... - if ( isNonNegativeInteger( arguments[ 0 ] ) ) { - return typedarray( ctor, arguments[ 0 ], dtype ); - } - // Check if provided an array-like object containing data elements... - if ( isCollection( arguments[ 0 ] ) ) { - arr = arguments[ 0 ]; - len = arr.length; - if ( isComplex128Array( arr ) ) { - arr = reinterpret128( arr, 0 ); - } else if ( isComplex64Array( arr ) ) { - arr = reinterpret64( arr, 0 ); - } else if ( /^complex/.test( dtype ) ) { - // Assume we've been provided an array of interleaved real and imaginary components... - len /= 2; - } - out = typedarray( ctor, len, dtype ); - if ( out === null ) { - return out; - } - if ( isCmplx128Array( out ) || isCmplx64Array( out ) ) { - out.set( arr ); - return out; - } - // Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other "unsafe" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things... - get = accessors( adtype( arr ) ).accessors[ 0 ]; - set = accessors( dtype ).accessors[ 1 ]; - for ( i = 0; i < len; i++ ) { - set( out, i, get( arr, i ) ); - } - return out; - } - throw new TypeError( format( '01H2r,N0', arguments[ 0 ] ) ); - } - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {NonNegativeInteger} [len=0] - array length - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function calloc() { - var nargs; - var out; - var tmp; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - out = malloc(); - } else if ( nargs === 1 ) { - out = malloc( arguments[ 0 ] ); - } else { - out = malloc( arguments[ 0 ], arguments[ 1 ] ); - } - if ( out !== null ) { - // Initialize the memory... - if ( isCmplx128Array( out ) ) { - tmp = reinterpret128( out, 0 ); - } else if ( isCmplx64Array( out ) ) { - tmp = reinterpret64( out, 0 ); - } else { - tmp = out; - } - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = 0.0; - } - } - return out; - } - - /** - * Frees a typed array or typed array buffer. - * - * ## Notes - * - * - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., "freeing" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool. - * - * @private - * @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free - * @throws {TypeError} must provide a typed array or typed array buffer - * @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed - */ - function free( buf ) { - var n; - var p; - var i; - if ( isTypedArrayLike( buf ) && buf.buffer ) { - buf = buf.buffer; - } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( '01H2s,N1', buf ) ); - } - if ( buf.byteLength > 0 ) { - n = floor( log2( buf.byteLength ) ); - - // Prohibit "freeing" array buffers which would potentially allow users to circumvent high water mark limits: - n = min( pool.length-1, n ); - - // Ensure that we do not attempt to free the same buffer more than once... - p = pool[ n ]; - for ( i = 0; i < p.length; i++ ) { - if ( p[ i ] === buf ) { - return false; - } - } - // Add the buffer to our pool of free buffers: - p.push( buf ); - } - return true; - } - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @private - */ - function clear() { - var i; - for ( i = 0; i < pool.length; i++ ) { - pool[ i ].length = 0; - } - nbytes = 0; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6c12a4e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Typed array pool. -* -* @module @stdlib/array-pool -* -* @example -* var typedarraypool = require( '@stdlib/array-pool' ); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8f69ee3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,63 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @name typedarraypool -* @type {Function} -* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a valid array length or an array-like object -* @throws {TypeError} must provide a recognized data type -* @returns {(TypedArray|null)} typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -var typedarraypool = factory(); - - -// EXPORTS // - -module.exports = typedarraypool; diff --git a/lib/pool.js b/lib/pool.js deleted file mode 100644 index 5abd287..0000000 --- a/lib/pool.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Initializes a cache for pooled typed array buffers. -* -* @private -* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size -* @returns {ArrayArray} initialized cache -*/ -function pool( n ) { - var out; - var i; - - out = []; - for ( i = 0; i < n+1; i++ ) { - out.push( [] ); - } - return out; -} - - -// EXPORTS // - -module.exports = pool; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 95667c7..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'highWaterMark': 1024 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '01H2V,FD', options ) ); - } - if ( hasOwnProp( options, 'highWaterMark' ) ) { - opts.highWaterMark = options.highWaterMark; - if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( '01H2t,G9', 'highWaterMark', opts.highWaterMark ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 6ff9938..bd7b179 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Typed array pool.", "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,76 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessors": "^0.1.0", - "@stdlib/array-buffer": "^0.1.0", - "@stdlib/array-dtype": "^0.1.0", - "@stdlib/array-typed-ctors": "^0.1.0", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-arraybuffer": "^0.1.1", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-complex128array": "^0.1.0", - "@stdlib/assert-is-complex64array": "^0.1.0", - "@stdlib/assert-is-nonnegative-integer": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/assert-is-string": "^0.1.1", - "@stdlib/assert-is-typed-array-like": "^0.1.0", - "@stdlib/math-base-special-ceil": "^0.1.1", - "@stdlib/math-base-special-ceil2": "^0.1.0", - "@stdlib/math-base-special-floor": "^0.1.1", - "@stdlib/math-base-special-log2": "^0.1.1", - "@stdlib/math-base-special-min": "^0.1.1", - "@stdlib/strided-base-reinterpret-complex128": "^0.1.1", - "@stdlib/strided-base-reinterpret-complex64": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.1.0", - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-float32": "^0.1.1", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/array-int16": "^0.1.1", - "@stdlib/array-int32": "^0.1.1", - "@stdlib/array-int8": "^0.1.1", - "@stdlib/array-uint16": "^0.1.1", - "@stdlib/array-uint32": "^0.1.1", - "@stdlib/array-uint8": "^0.1.1", - "@stdlib/array-uint8c": "^0.1.1", - "@stdlib/assert-instance-of": "^0.1.1", - "@stdlib/assert-is-complex-typed-array": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-typed-array": "^0.1.0", - "@stdlib/bench": "^0.2.0", - "@stdlib/complex-float32": "^0.1.1", - "@stdlib/complex-float64": "^0.1.1", - "@stdlib/complex-imag": "^0.1.1", - "@stdlib/complex-imagf": "^0.1.1", - "@stdlib/complex-real": "^0.1.1", - "@stdlib/complex-realf": "^0.1.1", - "@stdlib/math-base-special-pow": "^0.1.0", - "@stdlib/random-base-randu": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..86e0e2f --- /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.factory.js b/test/test.factory.js deleted file mode 100644 index 396aee2..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,2240 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function (no options)', function test( t ) { - t.strictEqual( typeof factory(), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - t.strictEqual( typeof factory( {} ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided a `highWaterMark` option which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (length)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a function which returns a typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, length)', function test( t ) { - var typedarraypool = factory(); - var arr; - - arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a `malloc` method which is a circular reference', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - var buf; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the returned function is a property which returns the pool\'s high water mark', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function supports specifying a high water mark which limits the total amount of memory a pool can allocate', function test( t ) { - var typedarraypool; - var arr1; - var arr2; - - typedarraypool = factory({ - 'highWaterMark': 64 // bytes - }); - - typedarraypool.clear(); - - arr1 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr1.length, 8, 'returns expected value' ); - t.strictEqual( arr1.byteLength, 64, 'returns expected value' ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - typedarraypool.free( arr1 ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Create an array which is less than or equal to the high water mark: - arr2 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr2.length, 8, 'returns expected value' ); - t.strictEqual( arr2.byteLength, 64, 'returns expected value' ); - - typedarraypool.free( arr2 ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a property which returns the total number of accumulated bytes', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var typedarraypool; - var arrs; - var i; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 54aa5ee..0000000 --- a/test/test.js +++ /dev/null @@ -1,1797 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var typedarraypool = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -}); From 2cdfaedf82b508911fb9ababc7518611b33a369e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 14:18:57 +0000 Subject: [PATCH 052/103] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index edfecbe..ae28056 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -34,7 +34,7 @@ var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); var accessors = require( '@stdlib/array-base-accessors' ); var adtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ArrayBuffer = require( '@stdlib/array-buffer' ); var ceil = require( '@stdlib/math-base-special-ceil' ); var floor = require( '@stdlib/math-base-special-floor' ); @@ -226,7 +226,7 @@ function factory( options ) { } ctor = ctors( dtype ); if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '01H2Y,KZ', dtype ) ); } if ( nargs <= 0 ) { return new ctor( 0 ); @@ -263,7 +263,7 @@ function factory( options ) { } return out; } - throw new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) ); + throw new TypeError( format( '01H2r,N0', arguments[ 0 ] ) ); } /** @@ -329,7 +329,7 @@ function factory( options ) { if ( isTypedArrayLike( buf ) && buf.buffer ) { buf = buf.buffer; } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) ); + throw new TypeError( format( '01H2s,N1', buf ) ); } if ( buf.byteLength > 0 ) { n = floor( log2( buf.byteLength ) ); diff --git a/lib/validate.js b/lib/validate.js index ce54890..95667c7 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '01H2V,FD', options ) ); } if ( hasOwnProp( options, 'highWaterMark' ) ) { opts.highWaterMark = options.highWaterMark; if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) ); + return new TypeError( format( '01H2t,G9', 'highWaterMark', opts.highWaterMark ) ); } } return null; diff --git a/package.json b/package.json index cf5910b..b56d137 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "@stdlib/math-base-special-min": "^0.1.1", "@stdlib/strided-base-reinterpret-complex128": "^0.1.1", "@stdlib/strided-base-reinterpret-complex64": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From 71cacb9de85ce72ed8d28ddc01b056dc8ede5a74 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 12:35:43 +0000 Subject: [PATCH 053/103] Remove files --- index.d.ts | 359 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6541 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 c6a3785..0000000 --- a/index.d.ts +++ /dev/null @@ -1,359 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; -import ArrayBuffer = require( '@stdlib/array-buffer' ); - -/** -* Typed array or null. -*/ -type TypedArrayOrNull = RealOrComplexTypedArray | null; - -/** -* Interface defining pool options. -*/ -interface Options { - /** - * Maximum total memory which can be allocated. - */ - highWaterMark?: number; -} - -/** -* Pool interface. -*/ -interface Pool { - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr = typedarraypool(); - * // returns [] - * - * @example - * var arr = typedarraypool( 'float32' ); - * // returns [] - */ - ( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * // Allocate an array of doubles: - * var arr = typedarraypool( 5, 'float64' ); - * // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * typedarraypool.free( arr ); - * - * @example - * var arr1 = typedarraypool( [ 0.5, 0.5, 0.5 ] ); - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * @example - * var arr1 = [ 0.5, 0.5, 0.5 ]; - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - */ - ( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc(); - * // returns [] - * - * var arr2 = typedarraypool.calloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param length - typed array length - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc( 5 ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * var arr2 = typedarraypool.calloc( 5, 'uint8' ); - * // returns [ 0, 0, 0, 0, 0 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( length: number, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc(); - * // returns [] - * - * var arr2 = typedarraypool.malloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc( 5 ); - * // returns - * - * var arr2 = typedarraypool.malloc( 5, 'uint8' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 5.0, -3.0, 2.0 ] ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr2 = typedarraypool.malloc( arr1 ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr3 = typedarraypool.malloc( arr1, 'int32' ); - * // returns [ 5, -3, 2 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * typedarraypool.free( arr3 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ] ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * var arr2 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ], 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Frees a typed array or typed array buffer for use in a future allocation. - * - * @param buf - typed array or typed array buffer to free - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array for use in a future allocation: - * typedarraypool.free( arr ); - * - * // Create another typed array: - * arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array buffer for use in a future allocation: - * typedarraypool.free( arr.buffer ); - */ - free( buf: RealOrComplexTypedArray | ArrayBuffer ): void; - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr ); - * - * // ... - * - * // Clear all freed buffers: - * typedarraypool.clear(); - */ - clear(): void; - - /** - * Read-only property returning the pool's high water mark. - * - * ## Notes - * - * - Once a high water mark is reached, typed array allocation fails. - * - * @example - * var limit = typedarraypool.highWaterMark; - * // returns - */ - readonly highWaterMark: number; - - /** - * Read-only property returning the total number of allocated bytes. - * - * @example - * var arr = typedarraypool( 5, 'float64' ); - * - * var nbytes = typedarraypool.nbytes; - * // returns - */ - readonly nbytes: number; - - /** - * Creates a typed array pool. - * - * @param options - pool options - * @param options.highWaterMark - maximum total memory which can be allocated - * @throws must provide valid options - * @returns allocator - * - * @example - * var allocator = typedarraypool.factory(); - * - * // Allocate an array of doubles: - * var arr = allocator( 5, 'float64' ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * allocator.free( arr ); - */ - factory( options?: Options ): Pool; -} - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @param arg - an array length or an array-like object -* @param dtype - data type (default: 'float64') -* @returns typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -declare var typedarraypool: Pool; - - -// EXPORTS // - -export = typedarraypool; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ceb156c..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessors@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.1.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.1.0-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.1.1-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.1.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";function k(e,t){return y(t)?w(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(c("01H2t,G9","highWaterMark",e.highWaterMark)):null:new TypeError(c("01H2V,FD",t))}function M(e){var t,r;for(t=[],r=0;rH.highWaterMark?null:(t=new j(e),w+=e,t)}function G(e,t,r){var s;return 0===t?new e(0):null===(s=F(u(t)*W[r]))?s:new e(s,0,t)}function K(){var e,i,n,l,j,v,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(n=d(i)))throw new TypeError(c("01H2Y,KZ",i));if(e<=0)return new n(0);if(r(arguments[0]))return G(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,m(l)?l=h(l,0):o(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=G(n,u,i)))return j;if(L(j)||T(j))return j.set(l),j;for(g=p(f(l)).accessors[0],v=p(i).accessors[1],b=0;b0){for(t=g(b(e.byteLength)),t=x(E.length-1,t),r=E[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '01H2Y,KZ', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = accessors( adtype( arr ) ).accessors[ 0 ];\n\t\t\tset = accessors( dtype ).accessors[ 1 ];\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '01H2r,N0', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( '01H2s,N1', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","accessors","adtype","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;ywEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,WAAY,gBAAiBP,EAAKI,gBAG3D,KARC,IAAIE,UAAWC,EAAQ,WAAYN,GAS5C,CC/BA,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,iHCaIG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EC/EO,CACNI,cAAiB,kBD+EbkB,UAAUC,SACdF,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOgB,EAAYC,EAAMC,EAAM1B,EAAKI,iBACpCgB,EAAS,EAETO,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB5B,EAAKI,eAC3C4B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOb,CACP,CASD,SAASc,EAAazB,GACrB,IAAI0B,EACAxB,EAMJ,OAHAA,EAAIe,EAAMjB,IAGDD,EAAKe,QAAUf,EAAMG,GAAIY,OAC1Bf,EAAMG,GAAIyB,MAGbhB,EAAOX,EAAIT,EAAKI,cACb,MAER+B,EAAM,IAAIE,EAAa5B,GAGvBW,GAAUX,EAEH0B,EACP,CAWD,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,EACzB,CAkBD,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAtB,EACAP,EACAmC,EACAC,EACAN,EACA7B,EAUJ,GALC8B,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAOzB,EAAO2B,IAEb,MAAM,IAAInC,UAAWC,EAAQ,WAAYkC,IAE1C,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKlC,EAAsBiB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAvB,EAAMK,UAAW,IACPC,OACL0B,EAAmBhC,GACvBA,EAAMiC,EAAgBjC,EAAK,GAChBkC,EAAkBlC,GAC7BA,EAAMmC,EAAenC,EAAK,GACf,WAAWoC,KAAMZ,KAE5BD,GAAO,GAGK,QADb9B,EAAM4B,EAAYC,EAAMC,EAAKC,IAE5B,OAAO/B,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAImC,IAAK5B,GACFP,EAKR,IAFAoC,EAAMQ,EAAWC,EAAQtC,IAAQqC,UAAW,GAC5CT,EAAMS,EAAWb,GAAQa,UAAW,GAC9B3C,EAAI,EAAGA,EAAI6B,EAAK7B,IACrBkC,EAAKnC,EAAKC,EAAGmC,EAAK7B,EAAKN,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,WAAYe,UAAW,IACpD,CAgBD,SAASO,IACR,IAAIe,EACAlC,EACA8C,EACA7C,EAUJ,GAAa,QANZD,EADc,KADfkC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCkC,EADItC,EAAiBR,GACfwC,EAAgBxC,EAAK,GAChBM,EAAgBN,GACrB0C,EAAe1C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAI6C,EAAIjC,OAAQZ,IAC5B6C,EAAK7C,GAAM,EAGb,OAAOD,CACP,CAcD,SAASoB,EAAMK,GACd,IAAI1B,EACAgD,EACA9C,EACJ,GAAK+C,EAAkBvB,IAASA,EAAIwB,OACnCxB,EAAMA,EAAIwB,YACJ,IAAMC,EAAezB,GAC3B,MAAM,IAAI7B,UAAWC,EAAQ,WAAY4B,IAE1C,GAAKA,EAAI0B,WAAa,EAAI,CAQzB,IAPApD,EAAIqD,EAAOpC,EAAMS,EAAI0B,aAGrBpD,EAAIsD,EAAKvD,EAAKe,OAAO,EAAGd,GAGxBgD,EAAIjD,EAAMC,GACJE,EAAI,EAAGA,EAAI8C,EAAElC,OAAQZ,IAC1B,GAAK8C,EAAG9C,KAAQwB,EACf,OAAO,EAITsB,EAAE7C,KAAMuB,EACR,CACD,OAAO,CACP,CAOD,SAASJ,IACR,IAAIpB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKe,OAAQZ,IAC7BH,EAAMG,GAAIY,OAAS,EAEpBH,EAAS,CACT,CACF,CEnTG,IAAC4C,EAAiB7C,ICPrBQ,EAAAsC,EAAA,UAAA9C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 86e0e2f..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 7b5c71b47621b14f7ae7fa2aea375ace1c8004cb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 12:38:28 +0000 Subject: [PATCH 054/103] 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 | 43 +- benchmark/benchmark.calloc.js | 246 - benchmark/benchmark.factory.js | 71 - benchmark/benchmark.js | 246 - benchmark/benchmark.length.complex128.js | 102 - benchmark/benchmark.length.complex64.js | 102 - benchmark/benchmark.length.float32.js | 102 - benchmark/benchmark.length.float64.js | 102 - benchmark/benchmark.length.int16.js | 102 - benchmark/benchmark.length.int32.js | 102 - benchmark/benchmark.length.int8.js | 102 - benchmark/benchmark.length.uint16.js | 102 - benchmark/benchmark.length.uint32.js | 102 - benchmark/benchmark.length.uint8.js | 102 - benchmark/benchmark.length.uint8c.js | 102 - benchmark/benchmark.malloc.js | 246 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 347 -- docs/types/test.ts | 193 - examples/index.js | 80 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/bytes_per_element.json | 13 - lib/defaults.js | 42 - lib/factory.js | 370 -- lib/index.js | 56 - lib/main.js | 63 - lib/pool.js | 44 - lib/validate.js | 66 - package.json | 97 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 2240 -------- test/test.js | 1797 ------ 62 files changed, 6206 insertions(+), 10633 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.calloc.js delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.complex128.js delete mode 100644 benchmark/benchmark.length.complex64.js delete mode 100644 benchmark/benchmark.length.float32.js delete mode 100644 benchmark/benchmark.length.float64.js delete mode 100644 benchmark/benchmark.length.int16.js delete mode 100644 benchmark/benchmark.length.int32.js delete mode 100644 benchmark/benchmark.length.int8.js delete mode 100644 benchmark/benchmark.length.uint16.js delete mode 100644 benchmark/benchmark.length.uint32.js delete mode 100644 benchmark/benchmark.length.uint8.js delete mode 100644 benchmark/benchmark.length.uint8c.js delete mode 100644 benchmark/benchmark.malloc.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/bytes_per_element.json delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/pool.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index a8a3a50..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-12-01T06:03:14.713Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ea35f20..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/array/pool) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6f7c875..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/array/pool) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 4f5a65c..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -493,7 +492,7 @@ console.log( 'nbytes: %d', typedarray.nbytes ); ## 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]. @@ -559,7 +558,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm diff --git a/benchmark/benchmark.calloc.js b/benchmark/benchmark.calloc.js deleted file mode 100644 index e5a1c77..0000000 --- a/benchmark/benchmark.calloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':calloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index f7cd676..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = typedarray.factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:highWaterMark', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'highWaterMark': 0 - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.highWaterMark = i; - f = typedarray.factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 8a023d2..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.complex128.js b/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 47b623b..0000000 --- a/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex64.js b/benchmark/benchmark.length.complex64.js deleted file mode 100644 index 40a412b..0000000 --- a/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float32.js b/benchmark/benchmark.length.float32.js deleted file mode 100644 index 0227ed7..0000000 --- a/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float64.js b/benchmark/benchmark.length.float64.js deleted file mode 100644 index 2dbac1c..0000000 --- a/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int16.js b/benchmark/benchmark.length.int16.js deleted file mode 100644 index e2a8adc..0000000 --- a/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int32.js b/benchmark/benchmark.length.int32.js deleted file mode 100644 index e4df0aa..0000000 --- a/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int8.js b/benchmark/benchmark.length.int8.js deleted file mode 100644 index 7ceac11..0000000 --- a/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint16.js b/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 9a532b6..0000000 --- a/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint32.js b/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 98f2d7f..0000000 --- a/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8.js b/benchmark/benchmark.length.uint8.js deleted file mode 100644 index 8359249..0000000 --- a/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8c.js b/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index d47d023..0000000 --- a/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.malloc.js b/benchmark/benchmark.malloc.js deleted file mode 100644 index d4eea72..0000000 --- a/benchmark/benchmark.malloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':malloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 9689761..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/array/pool" -%% click B href "https://github.com/stdlib-js/array-pool/tree/main" -%% click C href "https://github.com/stdlib-js/array-pool/tree/production" -%% click D href "https://github.com/stdlib-js/array-pool/tree/esm" -%% click E href "https://github.com/stdlib-js/array-pool/tree/deno" -%% click F href "https://github.com/stdlib-js/array-pool/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/pool -[production-url]: https://github.com/stdlib-js/array-pool/tree/production -[deno-url]: https://github.com/stdlib-js/array-pool/tree/deno -[umd-url]: https://github.com/stdlib-js/array-pool/tree/umd -[esm-url]: https://github.com/stdlib-js/array-pool/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 5160b6f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import typedarraypool from '../docs/types/index'; -export = typedarraypool; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 9d31d69..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var l=function(n,i){return function(){return i||n((i={exports:{}}).exports,i),i.exports}};var k=l(function(kr,M){ -function D(){return{highWaterMark:9007199254740992}}M.exports=D -});var E=l(function(Ar,W){ -var G=require('@stdlib/assert-is-plain-object/dist'),H=require('@stdlib/assert-has-own-property/dist'),J=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,A=require('@stdlib/error-tools-fmtprodmsg/dist');function K(n,i){return G(i)?H(i,"highWaterMark")&&(n.highWaterMark=i.highWaterMark,!J(n.highWaterMark))?new TypeError(A('01H2t',"highWaterMark",n.highWaterMark)):null:new TypeError(A('01H2V',i));}W.exports=K -});var C=l(function(Wr,T){ -function Q(n){var i,u;for(i=[],u=0;uv.highWaterMark?null:(e=new ur(r),i+=r,e)}function d(r,e,t){var a;return e===0?new r(0):(a=_(lr(e)*hr[t]),a===null?a:new r(a,0,e))}function s(){var r,e,t,a,o,x,w,c,f;if(r=arguments.length,r&&X(arguments[r-1])?(r-=1,e=arguments[r]):e="float64",t=y(e),t===null)throw new TypeError(m('01H2Y',e));if(r<=0)return new t(0);if(Z(arguments[0]))return d(t,arguments[0],e);if($(arguments[0])){if(a=arguments[0],c=a.length,tr(a)?a=P(a,0):ar(a)?a=b(a,0):/^complex/.test(e)&&(c/=2),o=d(t,c,e),o===null)return o;if(L(o)||N(o))return o.set(a),o;for(w=B(nr(a)).accessors[0],x=B(e).accessors[1],f=0;f0){for(e=or(p(r.byteLength)),e=vr(u.length-1,e),t=u[e],a=0;a[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = accessors( adtype( arr ) ).accessors[ 0 ];\n\t\t\tset = accessors( dtype ).accessors[ 1 ];\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nmodule.exports = typedarraypool;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* var typedarraypool = require( '@stdlib/array-pool' );\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,cAAiB,gBAClB,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,eAAgB,IACzCD,EAAK,cAAgBC,EAAQ,cACxB,CAACJ,EAAsBG,EAAK,aAAc,GACvC,IAAI,UAAWF,EAAQ,2EAA4E,gBAAiBE,EAAK,aAAc,CAAE,EAG3I,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cA6BA,SAASC,EAAM,EAAI,CAClB,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAI,EAAE,EAAGA,IACrBD,EAAI,KAAM,CAAC,CAAE,EAEd,OAAOA,CACR,CAKAF,EAAO,QAAUC,IC3CjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,QAAW,EACX,QAAW,EACX,MAAS,EACT,MAAS,EACT,KAAQ,EACR,OAAU,EACV,OAAU,EACV,MAAS,EACT,OAAU,EACT,UAAa,EACb,WAAc,EAChB,ICZA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAe,QAAS,8BAA+B,EACvDC,GAAmB,QAAS,oCAAqC,EACjEC,GAAgB,QAAS,+BAAgC,EACzDC,GAAmB,QAAS,kCAAmC,EAC/DC,GAAoB,QAAS,mCAAoC,EACjEC,EAAc,QAAS,uDAAwD,EAC/EC,GAAsB,QAAS,uDAAwD,EACvFC,EAAQ,QAAS,2BAA4B,EAC7CC,EAAgB,QAAS,4CAA6C,EACtEC,EAAiB,QAAS,6CAA8C,EACxEC,EAAY,QAAS,8BAA+B,EACpDC,GAAS,QAAS,qBAAsB,EACxCC,EAAS,QAAS,uBAAwB,EAC1CC,GAAc,QAAS,sBAAuB,EAC9CC,GAAO,QAAS,gCAAiC,EACjDC,GAAQ,QAAS,iCAAkC,EACnDC,GAAQ,QAAS,iCAAkC,EACnDC,EAAO,QAAS,gCAAiC,EACjDC,GAAM,QAAS,+BAAgC,EAC/CC,GAAW,IACXC,GAAW,IACXC,GAAa,IACbC,GAAoB,IAKpBC,GAAiBhB,EAAO,WAAY,EACpCiB,GAAkBjB,EAAO,YAAa,EAY1C,SAASkB,EAAgBC,EAAM,CAC9B,OAASA,aAAeH,EACzB,CASA,SAASI,EAAiBD,EAAM,CAC/B,OAASA,aAAeF,EACzB,CA6BA,SAASI,GAASC,EAAU,CAC3B,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,EAAOb,GAAS,EACX,UAAU,SACdc,EAAMb,GAAUY,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAAF,EAAOV,GAAYP,GAAMG,EAAMe,EAAK,aAAc,CAAE,CAAE,EACtDF,EAAS,EAETzB,EAAa6B,EAAQ,SAAUA,CAAO,EACtC7B,EAAa6B,EAAQ,SAAUC,CAAO,EACtC9B,EAAa6B,EAAQ,OAAQE,CAAK,EAClC/B,EAAa6B,EAAQ,QAASG,CAAM,EACpChC,EAAa6B,EAAQ,gBAAiBF,EAAK,aAAc,EACzD1B,GAAqB4B,EAAQ,SAAUI,CAAS,EAEzCJ,EAQP,SAASI,GAAW,CACnB,OAAOR,CACR,CASA,SAASS,EAAaC,EAAI,CACzB,IAAIC,EACAC,EAMJ,OAHAA,EAAIzB,EAAMuB,CAAE,EAGPE,EAAIX,EAAK,QAAUA,EAAMW,CAAE,EAAE,OAC1BX,EAAMW,CAAE,EAAE,IAAI,EAGjBZ,EAAOU,EAAIR,EAAK,cACb,MAERS,EAAM,IAAI5B,GAAa2B,CAAE,EAGzBV,GAAUU,EAEHC,EACR,CAWA,SAASE,EAAYC,EAAMC,EAAKC,EAAQ,CACvC,IAAIL,EACJ,OAAKI,IAAQ,EACL,IAAID,EAAM,CAAE,GAEpBH,EAAMF,EAAavB,GAAO6B,CAAI,EAAEvB,GAAmBwB,CAAM,CAAE,EACtDL,IAAQ,KACLA,EAED,IAAIG,EAAMH,EAAK,EAAGI,CAAI,EAC9B,CAkBA,SAASX,GAAS,CACjB,IAAIa,EACAD,EACAF,EACAlB,EACAsB,EACAC,EACAC,EACAL,EACAH,EAUJ,GARAK,EAAQ,UAAU,OACbA,GAASjD,EAAU,UAAWiD,EAAM,CAAE,CAAE,GAC5CA,GAAS,EACTD,EAAQ,UAAWC,CAAM,GAEzBD,EAAQ,UAETF,EAAOrC,EAAOuC,CAAM,EACfF,IAAS,KACb,MAAM,IAAI,UAAWhC,EAAQ,sEAAuEkC,CAAM,CAAE,EAE7G,GAAKC,GAAS,EACb,OAAO,IAAIH,EAAM,CAAE,EAGpB,GAAK7C,EAAsB,UAAW,CAAE,CAAE,EACzC,OAAO4C,EAAYC,EAAM,UAAW,CAAE,EAAGE,CAAM,EAGhD,GAAK9C,EAAc,UAAW,CAAE,CAAE,EAAI,CAYrC,GAXA0B,EAAM,UAAW,CAAE,EACnBmB,EAAMnB,EAAI,OACLtB,GAAmBsB,CAAI,EAC3BA,EAAMjB,EAAgBiB,EAAK,CAAE,EAClBvB,GAAkBuB,CAAI,EACjCA,EAAMlB,EAAekB,EAAK,CAAE,EACjB,WAAW,KAAMoB,CAAM,IAElCD,GAAO,GAERG,EAAML,EAAYC,EAAMC,EAAKC,CAAM,EAC9BE,IAAQ,KACZ,OAAOA,EAER,GAAKrB,EAAiBqB,CAAI,GAAKvB,EAAgBuB,CAAI,EAClD,OAAAA,EAAI,IAAKtB,CAAI,EACNsB,EAKR,IAFAE,EAAMxC,EAAWC,GAAQe,CAAI,CAAE,EAAE,UAAW,CAAE,EAC9CuB,EAAMvC,EAAWoC,CAAM,EAAE,UAAW,CAAE,EAChCJ,EAAI,EAAGA,EAAIG,EAAKH,IACrBO,EAAKD,EAAKN,EAAGQ,EAAKxB,EAAKgB,CAAE,CAAE,EAE5B,OAAOM,CACR,CACA,MAAM,IAAI,UAAWpC,EAAQ,wGAAyG,UAAW,CAAE,CAAE,CAAE,CACxJ,CAgBA,SAASuB,GAAS,CACjB,IAAIY,EACAC,EACAG,EACAT,EAUJ,GARAK,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAMd,EAAO,EACFa,IAAU,EACrBC,EAAMd,EAAQ,UAAW,CAAE,CAAE,EAE7Bc,EAAMd,EAAQ,UAAW,CAAE,EAAG,UAAW,CAAE,CAAE,EAEzCc,IAAQ,KASZ,IAPKrB,EAAiBqB,CAAI,EACzBG,EAAM1C,EAAgBuC,EAAK,CAAE,EAClBvB,EAAgBuB,CAAI,EAC/BG,EAAM3C,EAAewC,EAAK,CAAE,EAE5BG,EAAMH,EAEDN,EAAI,EAAGA,EAAIS,EAAI,OAAQT,IAC5BS,EAAKT,CAAE,EAAI,EAGb,OAAOM,CACR,CAcA,SAASZ,EAAMK,EAAM,CACpB,IAAID,EACAY,EACAV,EACJ,GAAKzC,GAAkBwC,CAAI,GAAKA,EAAI,OACnCA,EAAMA,EAAI,eACC,CAACvC,GAAeuC,CAAI,EAC/B,MAAM,IAAI,UAAW7B,EAAQ,4EAA6E6B,CAAI,CAAE,EAEjH,GAAKA,EAAI,WAAa,EAAI,CAQzB,IAPAD,EAAIzB,GAAOE,EAAMwB,EAAI,UAAW,CAAE,EAGlCD,EAAItB,GAAKa,EAAK,OAAO,EAAGS,CAAE,EAG1BY,EAAIrB,EAAMS,CAAE,EACNE,EAAI,EAAGA,EAAIU,EAAE,OAAQV,IAC1B,GAAKU,EAAGV,CAAE,IAAMD,EACf,MAAO,GAITW,EAAE,KAAMX,CAAI,CACb,CACA,MAAO,EACR,CAOA,SAASJ,GAAQ,CAChB,IAAIK,EACJ,IAAMA,EAAI,EAAGA,EAAIX,EAAK,OAAQW,IAC7BX,EAAMW,CAAE,EAAE,OAAS,EAEpBZ,EAAS,CACV,CACD,CAKAjC,EAAO,QAAU+B,KCjXjB,IAAAyB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAU,IAmCVC,GAAiBD,GAAQ,EAK7BD,EAAO,QAAUE,KCnBjB,IAAIC,GAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,GAAU,IAKdF,GAAaC,EAAM,UAAWC,EAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isNonNegativeInteger", "format", "validate", "opts", "options", "require_pool", "__commonJSMin", "exports", "module", "pool", "out", "i", "require_bytes_per_element", "__commonJSMin", "exports", "module", "require_factory", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isCollection", "isTypedArrayLike", "isArrayBuffer", "isComplex64Array", "isComplex128Array", "setReadOnly", "setReadOnlyAccessor", "ctors", "reinterpret64", "reinterpret128", "accessors", "adtype", "format", "ArrayBuffer", "ceil", "floor", "ceil2", "log2", "min", "defaults", "validate", "createPool", "BYTES_PER_ELEMENT", "Complex64Array", "Complex128Array", "isCmplx64Array", "arr", "isCmplx128Array", "factory", "options", "nbytes", "pool", "opts", "err", "malloc", "calloc", "free", "clear", "getBytes", "arraybuffer", "n", "buf", "i", "typedarray", "ctor", "len", "dtype", "nargs", "out", "set", "get", "tmp", "p", "require_main", "__commonJSMin", "exports", "module", "factory", "typedarraypool", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5244595..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,347 +0,0 @@ - -{{alias}}( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - Memory is **uninitialized**, which means that the contents of a returned - typed array may contain sensitive contents. - - The function supports the following data types: - - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - The default typed array data type is `float64`. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}() - [] - > arr = {{alias}}( 'float32' ) - [] - - -{{alias}}( length[, dtype] ) - Returns an uninitialized typed array having a specified length from a typed - array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > arr = {{alias}}( 5, 'int32' ) - - - -{{alias}}( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - This method shares the same security vulnerabilities mentioned above. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc() - - > arr = {{alias}}.malloc( 'float32' ) - - - -{{alias}}.malloc( length[, dtype] ) - Returns a typed array having a specified length from a typed array memory - pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc( 5 ) - - > arr = {{alias}}.malloc( 5, 'int32' ) - - - -{{alias}}.malloc( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}.malloc( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.calloc( [dtype] ) - Returns a zero-initialized typed array from a typed array memory pool. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc() - [] - > arr = {{alias}}.calloc( 'float32' ) - [] - - -{{alias}}.calloc( length[, dtype] ) - Returns a zero-initialized typed array having a specified length from a - typed array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}.calloc( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}.free( buf ) - Frees a typed array or typed array buffer for use in a future allocation. - - Parameters - ---------- - buf: TypedArray|ArrayBuffer - Typed array or typed array buffer to free. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ) - - -{{alias}}.clear() - Clears the typed array pool allowing garbage collection of previously - allocated (and currently free) array buffers. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - > {{alias}}.clear() - - -{{alias}}.highWaterMark - Read-only property returning the pool's high water mark. - - Once a high water mark is reached, typed array allocation fails. - - Examples - -------- - > {{alias}}.highWaterMark - - -{{alias}}.nbytes - Read-only property returning the total number of allocated bytes. - - The returned value is the total accumulated value. Hence, anytime a pool - must allocate a new array buffer (i.e., more memory), the pool increments - this value. - - The only time this value is decremented is when a pool is cleared. - - This behavior means that, while allocated buffers which are never freed may, - in fact, be garbage collected, they continue to count against the high water - mark limit. - - Accordingly, you should *always* free allocated buffers in order to prevent - the pool from believing that non-freed buffers are continually in use. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.nbytes - - -{{alias}}.factory( [options] ) - Creates a typed array pool. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.highWaterMark: integer (optional) - Maximum total memory (in bytes) which can be allocated. - - Returns - ------- - fcn: Function - Function for creating typed arrays from a typed array memory pool. - - Examples - -------- - > var pool = {{alias}}.factory(); - > var arr1 = pool( 3, 'float64' ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 4336c42..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,193 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-empty */ -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import typedarraypool = require( './index' ); - - -// TESTS // - -// The function returns a typed array or null... -{ - typedarraypool(); // $ExpectType TypedArrayOrNull - typedarraypool( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the function is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool( true ); // $ExpectError - typedarraypool( false ); // $ExpectError - typedarraypool( null ); // $ExpectError - typedarraypool( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized data type... -{ - typedarraypool( 4, true ); // $ExpectError - typedarraypool( 4, false ); // $ExpectError - typedarraypool( 4, null ); // $ExpectError - typedarraypool( 4, 'abc' ); // $ExpectError - typedarraypool( 4, 123 ); // $ExpectError - typedarraypool( 4, [] ); // $ExpectError - typedarraypool( 4, {} ); // $ExpectError - typedarraypool( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an incorrect number of arguments... -{ - typedarraypool( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `malloc` method which returns a typed array or null... -{ - typedarraypool.malloc(); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.malloc( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `malloc` method is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool.malloc( true ); // $ExpectError - typedarraypool.malloc( false ); // $ExpectError - typedarraypool.malloc( null ); // $ExpectError - typedarraypool.malloc( {} ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.malloc( 4, true ); // $ExpectError - typedarraypool.malloc( 4, false ); // $ExpectError - typedarraypool.malloc( 4, null ); // $ExpectError - typedarraypool.malloc( 4, 'abc' ); // $ExpectError - typedarraypool.malloc( 4, 123 ); // $ExpectError - typedarraypool.malloc( 4, [] ); // $ExpectError - typedarraypool.malloc( 4, {} ); // $ExpectError - typedarraypool.malloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided an incorrect number of arguments... -{ - typedarraypool.malloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `calloc` method which returns a typed array or null... -{ - typedarraypool.calloc(); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `calloc` method is provided a first argument which is not a number... -{ - typedarraypool.calloc( 'abc' ); // $ExpectError - typedarraypool.calloc( true ); // $ExpectError - typedarraypool.calloc( false ); // $ExpectError - typedarraypool.calloc( null ); // $ExpectError - typedarraypool.calloc( {} ); // $ExpectError - typedarraypool.calloc( [] ); // $ExpectError - typedarraypool.calloc( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.calloc( 4, true ); // $ExpectError - typedarraypool.calloc( 4, false ); // $ExpectError - typedarraypool.calloc( 4, null ); // $ExpectError - typedarraypool.calloc( 4, 'abc' ); // $ExpectError - typedarraypool.calloc( 4, 123 ); // $ExpectError - typedarraypool.calloc( 4, [] ); // $ExpectError - typedarraypool.calloc( 4, {} ); // $ExpectError - typedarraypool.calloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided an incorrect number of arguments... -{ - typedarraypool.calloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `factory` method which returns a typed array pool.. -{ - typedarraypool.factory(); // $ExpectType Pool - typedarraypool.factory( { 'highWaterMark': 556 } ); // $ExpectType Pool -} - -// The compiler throws an error if the `factory` method is provided a `highWaterMark` option which is not a number... -{ - typedarraypool.factory( { 'highWaterMark': true } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': false } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': 'abc' } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': null } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': [] } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': {} } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an incorrect number of arguments... -{ - typedarraypool.factory( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` method which returns void... -{ - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.free( arr ); // $ExpectType void -} - -// The compiler throws an error if the `free` method is provided a first argument which is neither a typed array nor array buffer... -{ - typedarraypool.free( true ); // $ExpectError - typedarraypool.free( false ); // $ExpectError - typedarraypool.free( 123 ); // $ExpectError - typedarraypool.free( 'abc' ); // $ExpectError - typedarraypool.free( null ); // $ExpectError - typedarraypool.free( {} ); // $ExpectError - typedarraypool.free( ( x: number ): number => x ); // $ExpectError -} - -// Attached to the main export is a `clear` method which returns void... -{ - typedarraypool.clear(); // $ExpectType void -} - -// The compiler throws an error if the `clear` method is provided arguments... -{ - typedarraypool.clear( {} ); // $ExpectError - typedarraypool.clear( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `highWaterMark` property... -{ - typedarraypool.highWaterMark; // $ExpectType number -} - -// Attached to the main export is a `nbytes` property... -{ - typedarraypool.nbytes; // $ExpectType number -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 24a7846..0000000 --- a/examples/index.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 randu = require( '@stdlib/random-base-randu' ); -var typedarraypool = require( './../lib' ); - -// Create a typed array pool which can allocate at most 1GB: -var typedarray = typedarraypool.factory({ - 'highWaterMark': 1e9 -}); - -// Inspect the pool: -console.log( 'Max bytes: %d', typedarray.highWaterMark ); -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Allocate an array for storing double-precision floating-point numbers: -var arr1 = typedarray( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Fill the array... -var i; -for ( i = 0; i < arr1.length; i++ ) { - arr1[ i ] = randu(); -} - -// Inspect array contents: -console.log( arr1 ); - -// Free the array: -typedarray.free( arr1 ); - -// Allocate another array similar to the previous one: -var arr2 = typedarray( 5, 'float64' ); -// returns - -// Check that we have been returned a new typed array view: -console.log( arr2 === arr1 ); -// => false - -// Inspect array contents: -console.log( arr2 ); - -// Free the array: -typedarray.free( arr2 ); - -// Allocate an initialized array: -var arr3 = typedarray.calloc( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect array contents: -console.log( arr3 ); - -// Free the array: -typedarray.free( arr3 ); - -// Clear the pool: -typedarray.clear(); - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index de70cb0..c6a3785 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; import ArrayBuffer = require( '@stdlib/array-buffer' ); diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ceb156c --- /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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessors@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.1.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.1.0-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.1.1-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.1.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";function k(e,t){return y(t)?w(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(c("01H2t,G9","highWaterMark",e.highWaterMark)):null:new TypeError(c("01H2V,FD",t))}function M(e){var t,r;for(t=[],r=0;rH.highWaterMark?null:(t=new j(e),w+=e,t)}function G(e,t,r){var s;return 0===t?new e(0):null===(s=F(u(t)*W[r]))?s:new e(s,0,t)}function K(){var e,i,n,l,j,v,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(n=d(i)))throw new TypeError(c("01H2Y,KZ",i));if(e<=0)return new n(0);if(r(arguments[0]))return G(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,m(l)?l=h(l,0):o(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=G(n,u,i)))return j;if(L(j)||T(j))return j.set(l),j;for(g=p(f(l)).accessors[0],v=p(i).accessors[1],b=0;b0){for(t=g(b(e.byteLength)),t=x(E.length-1,t),r=E[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '01H2Y,KZ', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = accessors( adtype( arr ) ).accessors[ 0 ];\n\t\t\tset = accessors( dtype ).accessors[ 1 ];\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '01H2r,N0', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( '01H2s,N1', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","accessors","adtype","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;ywEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,WAAY,gBAAiBP,EAAKI,gBAG3D,KARC,IAAIE,UAAWC,EAAQ,WAAYN,GAS5C,CC/BA,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,iHCaIG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EC/EO,CACNI,cAAiB,kBD+EbkB,UAAUC,SACdF,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOgB,EAAYC,EAAMC,EAAM1B,EAAKI,iBACpCgB,EAAS,EAETO,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB5B,EAAKI,eAC3C4B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOb,CACP,CASD,SAASc,EAAazB,GACrB,IAAI0B,EACAxB,EAMJ,OAHAA,EAAIe,EAAMjB,IAGDD,EAAKe,QAAUf,EAAMG,GAAIY,OAC1Bf,EAAMG,GAAIyB,MAGbhB,EAAOX,EAAIT,EAAKI,cACb,MAER+B,EAAM,IAAIE,EAAa5B,GAGvBW,GAAUX,EAEH0B,EACP,CAWD,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,EACzB,CAkBD,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAtB,EACAP,EACAmC,EACAC,EACAN,EACA7B,EAUJ,GALC8B,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAOzB,EAAO2B,IAEb,MAAM,IAAInC,UAAWC,EAAQ,WAAYkC,IAE1C,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKlC,EAAsBiB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAvB,EAAMK,UAAW,IACPC,OACL0B,EAAmBhC,GACvBA,EAAMiC,EAAgBjC,EAAK,GAChBkC,EAAkBlC,GAC7BA,EAAMmC,EAAenC,EAAK,GACf,WAAWoC,KAAMZ,KAE5BD,GAAO,GAGK,QADb9B,EAAM4B,EAAYC,EAAMC,EAAKC,IAE5B,OAAO/B,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAImC,IAAK5B,GACFP,EAKR,IAFAoC,EAAMQ,EAAWC,EAAQtC,IAAQqC,UAAW,GAC5CT,EAAMS,EAAWb,GAAQa,UAAW,GAC9B3C,EAAI,EAAGA,EAAI6B,EAAK7B,IACrBkC,EAAKnC,EAAKC,EAAGmC,EAAK7B,EAAKN,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,WAAYe,UAAW,IACpD,CAgBD,SAASO,IACR,IAAIe,EACAlC,EACA8C,EACA7C,EAUJ,GAAa,QANZD,EADc,KADfkC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCkC,EADItC,EAAiBR,GACfwC,EAAgBxC,EAAK,GAChBM,EAAgBN,GACrB0C,EAAe1C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAI6C,EAAIjC,OAAQZ,IAC5B6C,EAAK7C,GAAM,EAGb,OAAOD,CACP,CAcD,SAASoB,EAAMK,GACd,IAAI1B,EACAgD,EACA9C,EACJ,GAAK+C,EAAkBvB,IAASA,EAAIwB,OACnCxB,EAAMA,EAAIwB,YACJ,IAAMC,EAAezB,GAC3B,MAAM,IAAI7B,UAAWC,EAAQ,WAAY4B,IAE1C,GAAKA,EAAI0B,WAAa,EAAI,CAQzB,IAPApD,EAAIqD,EAAOpC,EAAMS,EAAI0B,aAGrBpD,EAAIsD,EAAKvD,EAAKe,OAAO,EAAGd,GAGxBgD,EAAIjD,EAAMC,GACJE,EAAI,EAAGA,EAAI8C,EAAElC,OAAQZ,IAC1B,GAAK8C,EAAG9C,KAAQwB,EACf,OAAO,EAITsB,EAAE7C,KAAMuB,EACR,CACD,OAAO,CACP,CAOD,SAASJ,IACR,IAAIpB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKe,OAAQZ,IAC7BH,EAAMG,GAAIY,OAAS,EAEpBH,EAAS,CACT,CACF,CEnTG,IAAC4C,EAAiB7C,ICPrBQ,EAAAsC,EAAA,UAAA9C"} \ No newline at end of file diff --git a/lib/bytes_per_element.json b/lib/bytes_per_element.json deleted file mode 100644 index f97fe70..0000000 --- a/lib/bytes_per_element.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "float64": 8, - "float32": 4, - "int16": 2, - "int32": 4, - "int8": 1, - "uint16": 2, - "uint32": 4, - "uint8": 1, - "uint8c": 1, - "complex64": 8, - "complex128": 16 -} diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index a421711..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +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'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'highWaterMark': 9007199254740992 - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index ae28056..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,370 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var isComplex64Array = require( '@stdlib/assert-is-complex64array' ); -var isComplex128Array = require( '@stdlib/assert-is-complex128array' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var ctors = require( '@stdlib/array-typed-ctors' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var accessors = require( '@stdlib/array-base-accessors' ); -var adtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil = require( '@stdlib/math-base-special-ceil' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); -var log2 = require( '@stdlib/math-base-special-log2' ); -var min = require( '@stdlib/math-base-special-min' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var createPool = require( './pool.js' ); -var BYTES_PER_ELEMENT = require( './bytes_per_element.json' ); - - -// VARIABLES // - -var Complex64Array = ctors( 'complex64' ); -var Complex128Array = ctors( 'complex128' ); - - -// FUNCTIONS // - -/** -* Tests whether an array is a single-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a single-precision complex floating-point number array -*/ -function isCmplx64Array( arr ) { - return ( arr instanceof Complex64Array ); -} - -/** -* Tests whether an array is a double-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a double-precision complex floating-point number array -*/ -function isCmplx128Array( arr ) { - return ( arr instanceof Complex128Array ); -} - - -// MAIN // - -/** -* Creates a typed array pool. -* -* @param {Options} [options] - pool options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} allocator -* -* @example -* var typedarraypool = factory(); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -function factory( options ) { - var nbytes; - var pool; - var opts; - var err; - - opts = defaults(); - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - pool = createPool( ceil( log2( opts.highWaterMark ) ) ); - nbytes = 0; - - setReadOnly( malloc, 'malloc', malloc ); // circular reference - setReadOnly( malloc, 'calloc', calloc ); - setReadOnly( malloc, 'free', free ); - setReadOnly( malloc, 'clear', clear ); - setReadOnly( malloc, 'highWaterMark', opts.highWaterMark ); - setReadOnlyAccessor( malloc, 'nbytes', getBytes ); - - return malloc; - - /** - * Returns the number of allocated bytes. - * - * @private - * @returns {NonNegativeInteger} number of allocated bytes - */ - function getBytes() { - return nbytes; - } - - /** - * Returns an array buffer. - * - * @private - * @param {NonNegativeInteger} n - number of bytes - * @returns {(ArrayBuffer|null)} array buffer or null - */ - function arraybuffer( n ) { - var buf; - var i; - - // Convert the number of bytes to an index in our pool table: - i = log2( n ); - - // If we already have an available array buffer, use it... - if ( i < pool.length && pool[ i ].length ) { - return pool[ i ].pop(); - } - // Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate... - if ( nbytes+n > opts.highWaterMark ) { - return null; - } - buf = new ArrayBuffer( n ); - - // Update the running counter of allocated bytes: - nbytes += n; - - return buf; - } - - /** - * Returns a typed array. - * - * @private - * @param {Function} ctor - typed array constructor - * @param {NonNegativeInteger} len - view length - * @param {string} dtype - data type - * @returns {(TypedArray|null)} typed array or null - */ - function typedarray( ctor, len, dtype ) { - var buf; - if ( len === 0 ) { - return new ctor( 0 ); - } - buf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] ); - if ( buf === null ) { - return buf; - } - return new ctor( buf, 0, len ); - } - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length or an array-like object - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function malloc() { - var nargs; - var dtype; - var ctor; - var arr; - var out; - var set; - var get; - var len; - var i; - - nargs = arguments.length; - if ( nargs && isString( arguments[ nargs-1 ] ) ) { - nargs -= 1; - dtype = arguments[ nargs ]; - } else { - dtype = 'float64'; - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( '01H2Y,KZ', dtype ) ); - } - if ( nargs <= 0 ) { - return new ctor( 0 ); - } - // Check if provided a typed array length... - if ( isNonNegativeInteger( arguments[ 0 ] ) ) { - return typedarray( ctor, arguments[ 0 ], dtype ); - } - // Check if provided an array-like object containing data elements... - if ( isCollection( arguments[ 0 ] ) ) { - arr = arguments[ 0 ]; - len = arr.length; - if ( isComplex128Array( arr ) ) { - arr = reinterpret128( arr, 0 ); - } else if ( isComplex64Array( arr ) ) { - arr = reinterpret64( arr, 0 ); - } else if ( /^complex/.test( dtype ) ) { - // Assume we've been provided an array of interleaved real and imaginary components... - len /= 2; - } - out = typedarray( ctor, len, dtype ); - if ( out === null ) { - return out; - } - if ( isCmplx128Array( out ) || isCmplx64Array( out ) ) { - out.set( arr ); - return out; - } - // Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other "unsafe" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things... - get = accessors( adtype( arr ) ).accessors[ 0 ]; - set = accessors( dtype ).accessors[ 1 ]; - for ( i = 0; i < len; i++ ) { - set( out, i, get( arr, i ) ); - } - return out; - } - throw new TypeError( format( '01H2r,N0', arguments[ 0 ] ) ); - } - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {NonNegativeInteger} [len=0] - array length - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function calloc() { - var nargs; - var out; - var tmp; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - out = malloc(); - } else if ( nargs === 1 ) { - out = malloc( arguments[ 0 ] ); - } else { - out = malloc( arguments[ 0 ], arguments[ 1 ] ); - } - if ( out !== null ) { - // Initialize the memory... - if ( isCmplx128Array( out ) ) { - tmp = reinterpret128( out, 0 ); - } else if ( isCmplx64Array( out ) ) { - tmp = reinterpret64( out, 0 ); - } else { - tmp = out; - } - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = 0.0; - } - } - return out; - } - - /** - * Frees a typed array or typed array buffer. - * - * ## Notes - * - * - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., "freeing" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool. - * - * @private - * @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free - * @throws {TypeError} must provide a typed array or typed array buffer - * @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed - */ - function free( buf ) { - var n; - var p; - var i; - if ( isTypedArrayLike( buf ) && buf.buffer ) { - buf = buf.buffer; - } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( '01H2s,N1', buf ) ); - } - if ( buf.byteLength > 0 ) { - n = floor( log2( buf.byteLength ) ); - - // Prohibit "freeing" array buffers which would potentially allow users to circumvent high water mark limits: - n = min( pool.length-1, n ); - - // Ensure that we do not attempt to free the same buffer more than once... - p = pool[ n ]; - for ( i = 0; i < p.length; i++ ) { - if ( p[ i ] === buf ) { - return false; - } - } - // Add the buffer to our pool of free buffers: - p.push( buf ); - } - return true; - } - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @private - */ - function clear() { - var i; - for ( i = 0; i < pool.length; i++ ) { - pool[ i ].length = 0; - } - nbytes = 0; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6c12a4e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Typed array pool. -* -* @module @stdlib/array-pool -* -* @example -* var typedarraypool = require( '@stdlib/array-pool' ); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8f69ee3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,63 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @name typedarraypool -* @type {Function} -* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a valid array length or an array-like object -* @throws {TypeError} must provide a recognized data type -* @returns {(TypedArray|null)} typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -var typedarraypool = factory(); - - -// EXPORTS // - -module.exports = typedarraypool; diff --git a/lib/pool.js b/lib/pool.js deleted file mode 100644 index 5abd287..0000000 --- a/lib/pool.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Initializes a cache for pooled typed array buffers. -* -* @private -* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size -* @returns {ArrayArray} initialized cache -*/ -function pool( n ) { - var out; - var i; - - out = []; - for ( i = 0; i < n+1; i++ ) { - out.push( [] ); - } - return out; -} - - -// EXPORTS // - -module.exports = pool; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index 95667c7..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'highWaterMark': 1024 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '01H2V,FD', options ) ); - } - if ( hasOwnProp( options, 'highWaterMark' ) ) { - opts.highWaterMark = options.highWaterMark; - if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( '01H2t,G9', 'highWaterMark', opts.highWaterMark ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index b56d137..bd7b179 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Typed array pool.", "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,76 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessors": "^0.1.0", - "@stdlib/array-buffer": "^0.1.0", - "@stdlib/array-dtype": "^0.1.0", - "@stdlib/array-typed-ctors": "^0.1.0", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-arraybuffer": "^0.1.1", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-complex128array": "^0.1.0", - "@stdlib/assert-is-complex64array": "^0.1.0", - "@stdlib/assert-is-nonnegative-integer": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/assert-is-string": "^0.1.1", - "@stdlib/assert-is-typed-array-like": "^0.1.0", - "@stdlib/math-base-special-ceil": "^0.1.1", - "@stdlib/math-base-special-ceil2": "^0.1.0", - "@stdlib/math-base-special-floor": "^0.1.1", - "@stdlib/math-base-special-log2": "^0.1.1", - "@stdlib/math-base-special-min": "^0.1.1", - "@stdlib/strided-base-reinterpret-complex128": "^0.1.1", - "@stdlib/strided-base-reinterpret-complex64": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.1.0", - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-float32": "^0.1.1", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/array-int16": "^0.1.1", - "@stdlib/array-int32": "^0.1.1", - "@stdlib/array-int8": "^0.1.1", - "@stdlib/array-uint16": "^0.1.1", - "@stdlib/array-uint32": "^0.1.1", - "@stdlib/array-uint8": "^0.1.1", - "@stdlib/array-uint8c": "^0.1.1", - "@stdlib/assert-instance-of": "^0.1.1", - "@stdlib/assert-is-complex-typed-array": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-typed-array": "^0.1.0", - "@stdlib/bench": "^0.2.1", - "@stdlib/complex-float32": "^0.1.1", - "@stdlib/complex-float64": "^0.1.1", - "@stdlib/complex-imag": "^0.1.1", - "@stdlib/complex-imagf": "^0.1.1", - "@stdlib/complex-real": "^0.1.1", - "@stdlib/complex-realf": "^0.1.1", - "@stdlib/math-base-special-pow": "^0.1.0", - "@stdlib/random-base-randu": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..c427859 --- /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.factory.js b/test/test.factory.js deleted file mode 100644 index 396aee2..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,2240 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function (no options)', function test( t ) { - t.strictEqual( typeof factory(), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - t.strictEqual( typeof factory( {} ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided a `highWaterMark` option which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (length)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a function which returns a typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, length)', function test( t ) { - var typedarraypool = factory(); - var arr; - - arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a `malloc` method which is a circular reference', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - var buf; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the returned function is a property which returns the pool\'s high water mark', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function supports specifying a high water mark which limits the total amount of memory a pool can allocate', function test( t ) { - var typedarraypool; - var arr1; - var arr2; - - typedarraypool = factory({ - 'highWaterMark': 64 // bytes - }); - - typedarraypool.clear(); - - arr1 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr1.length, 8, 'returns expected value' ); - t.strictEqual( arr1.byteLength, 64, 'returns expected value' ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - typedarraypool.free( arr1 ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Create an array which is less than or equal to the high water mark: - arr2 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr2.length, 8, 'returns expected value' ); - t.strictEqual( arr2.byteLength, 64, 'returns expected value' ); - - typedarraypool.free( arr2 ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a property which returns the total number of accumulated bytes', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var typedarraypool; - var arrs; - var i; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 54aa5ee..0000000 --- a/test/test.js +++ /dev/null @@ -1,1797 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var typedarraypool = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -}); From 2d2059264ba50bdf03bc469f5a54d31fd0110e02 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 31 Dec 2023 11:03:06 +0000 Subject: [PATCH 055/103] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e61dcc2..9a6418f 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "@stdlib/math-base-special-min": "^0.1.1", "@stdlib/strided-base-reinterpret-complex128": "^0.1.1", "@stdlib/strided-base-reinterpret-complex64": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From 6eff880953485c0a8689ea23989c6bd48ad9e6b7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 31 Dec 2023 11:07:15 +0000 Subject: [PATCH 056/103] Remove files --- index.d.ts | 359 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6541 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 c6a3785..0000000 --- a/index.d.ts +++ /dev/null @@ -1,359 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike, RealOrComplexTypedArray, RealOrComplexDataType as DataType } from '@stdlib/types/array'; -import ArrayBuffer = require( '@stdlib/array-buffer' ); - -/** -* Typed array or null. -*/ -type TypedArrayOrNull = RealOrComplexTypedArray | null; - -/** -* Interface defining pool options. -*/ -interface Options { - /** - * Maximum total memory which can be allocated. - */ - highWaterMark?: number; -} - -/** -* Pool interface. -*/ -interface Pool { - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr = typedarraypool(); - * // returns [] - * - * @example - * var arr = typedarraypool( 'float32' ); - * // returns [] - */ - ( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * // Allocate an array of doubles: - * var arr = typedarraypool( 5, 'float64' ); - * // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * typedarraypool.free( arr ); - * - * @example - * var arr1 = typedarraypool( [ 0.5, 0.5, 0.5 ] ); - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * @example - * var arr1 = [ 0.5, 0.5, 0.5 ]; - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - */ - ( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc(); - * // returns [] - * - * var arr2 = typedarraypool.calloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param length - typed array length - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc( 5 ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * var arr2 = typedarraypool.calloc( 5, 'uint8' ); - * // returns [ 0, 0, 0, 0, 0 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( length: number, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc(); - * // returns [] - * - * var arr2 = typedarraypool.malloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc( 5 ); - * // returns - * - * var arr2 = typedarraypool.malloc( 5, 'uint8' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 5.0, -3.0, 2.0 ] ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr2 = typedarraypool.malloc( arr1 ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr3 = typedarraypool.malloc( arr1, 'int32' ); - * // returns [ 5, -3, 2 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * typedarraypool.free( arr3 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ] ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * var arr2 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ], 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Frees a typed array or typed array buffer for use in a future allocation. - * - * @param buf - typed array or typed array buffer to free - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array for use in a future allocation: - * typedarraypool.free( arr ); - * - * // Create another typed array: - * arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array buffer for use in a future allocation: - * typedarraypool.free( arr.buffer ); - */ - free( buf: RealOrComplexTypedArray | ArrayBuffer ): void; - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr ); - * - * // ... - * - * // Clear all freed buffers: - * typedarraypool.clear(); - */ - clear(): void; - - /** - * Read-only property returning the pool's high water mark. - * - * ## Notes - * - * - Once a high water mark is reached, typed array allocation fails. - * - * @example - * var limit = typedarraypool.highWaterMark; - * // returns - */ - readonly highWaterMark: number; - - /** - * Read-only property returning the total number of allocated bytes. - * - * @example - * var arr = typedarraypool( 5, 'float64' ); - * - * var nbytes = typedarraypool.nbytes; - * // returns - */ - readonly nbytes: number; - - /** - * Creates a typed array pool. - * - * @param options - pool options - * @param options.highWaterMark - maximum total memory which can be allocated - * @throws must provide valid options - * @returns allocator - * - * @example - * var allocator = typedarraypool.factory(); - * - * // Allocate an array of doubles: - * var arr = allocator( 5, 'float64' ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * allocator.free( arr ); - */ - factory( options?: Options ): Pool; -} - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @param arg - an array length or an array-like object -* @param dtype - data type (default: 'float64') -* @returns typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -declare var typedarraypool: Pool; - - -// EXPORTS // - -export = typedarraypool; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ceb156c..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.1.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.1.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessors@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.1.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.1.0-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.1.1-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.1.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";function k(e,t){return y(t)?w(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(c("01H2t,G9","highWaterMark",e.highWaterMark)):null:new TypeError(c("01H2V,FD",t))}function M(e){var t,r;for(t=[],r=0;rH.highWaterMark?null:(t=new j(e),w+=e,t)}function G(e,t,r){var s;return 0===t?new e(0):null===(s=F(u(t)*W[r]))?s:new e(s,0,t)}function K(){var e,i,n,l,j,v,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(n=d(i)))throw new TypeError(c("01H2Y,KZ",i));if(e<=0)return new n(0);if(r(arguments[0]))return G(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,m(l)?l=h(l,0):o(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=G(n,u,i)))return j;if(L(j)||T(j))return j.set(l),j;for(g=p(f(l)).accessors[0],v=p(i).accessors[1],b=0;b0){for(t=g(b(e.byteLength)),t=x(E.length-1,t),r=E[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '01H2Y,KZ', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = accessors( adtype( arr ) ).accessors[ 0 ];\n\t\t\tset = accessors( dtype ).accessors[ 1 ];\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '01H2r,N0', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( '01H2s,N1', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","accessors","adtype","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;ywEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,WAAY,gBAAiBP,EAAKI,gBAG3D,KARC,IAAIE,UAAWC,EAAQ,WAAYN,GAS5C,CC/BA,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,iHCaIG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EC/EO,CACNI,cAAiB,kBD+EbkB,UAAUC,SACdF,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOgB,EAAYC,EAAMC,EAAM1B,EAAKI,iBACpCgB,EAAS,EAETO,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB5B,EAAKI,eAC3C4B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOb,CACP,CASD,SAASc,EAAazB,GACrB,IAAI0B,EACAxB,EAMJ,OAHAA,EAAIe,EAAMjB,IAGDD,EAAKe,QAAUf,EAAMG,GAAIY,OAC1Bf,EAAMG,GAAIyB,MAGbhB,EAAOX,EAAIT,EAAKI,cACb,MAER+B,EAAM,IAAIE,EAAa5B,GAGvBW,GAAUX,EAEH0B,EACP,CAWD,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,EACzB,CAkBD,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAtB,EACAP,EACAmC,EACAC,EACAN,EACA7B,EAUJ,GALC8B,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAOzB,EAAO2B,IAEb,MAAM,IAAInC,UAAWC,EAAQ,WAAYkC,IAE1C,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKlC,EAAsBiB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAvB,EAAMK,UAAW,IACPC,OACL0B,EAAmBhC,GACvBA,EAAMiC,EAAgBjC,EAAK,GAChBkC,EAAkBlC,GAC7BA,EAAMmC,EAAenC,EAAK,GACf,WAAWoC,KAAMZ,KAE5BD,GAAO,GAGK,QADb9B,EAAM4B,EAAYC,EAAMC,EAAKC,IAE5B,OAAO/B,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAImC,IAAK5B,GACFP,EAKR,IAFAoC,EAAMQ,EAAWC,EAAQtC,IAAQqC,UAAW,GAC5CT,EAAMS,EAAWb,GAAQa,UAAW,GAC9B3C,EAAI,EAAGA,EAAI6B,EAAK7B,IACrBkC,EAAKnC,EAAKC,EAAGmC,EAAK7B,EAAKN,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,WAAYe,UAAW,IACpD,CAgBD,SAASO,IACR,IAAIe,EACAlC,EACA8C,EACA7C,EAUJ,GAAa,QANZD,EADc,KADfkC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCkC,EADItC,EAAiBR,GACfwC,EAAgBxC,EAAK,GAChBM,EAAgBN,GACrB0C,EAAe1C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAI6C,EAAIjC,OAAQZ,IAC5B6C,EAAK7C,GAAM,EAGb,OAAOD,CACP,CAcD,SAASoB,EAAMK,GACd,IAAI1B,EACAgD,EACA9C,EACJ,GAAK+C,EAAkBvB,IAASA,EAAIwB,OACnCxB,EAAMA,EAAIwB,YACJ,IAAMC,EAAezB,GAC3B,MAAM,IAAI7B,UAAWC,EAAQ,WAAY4B,IAE1C,GAAKA,EAAI0B,WAAa,EAAI,CAQzB,IAPApD,EAAIqD,EAAOpC,EAAMS,EAAI0B,aAGrBpD,EAAIsD,EAAKvD,EAAKe,OAAO,EAAGd,GAGxBgD,EAAIjD,EAAMC,GACJE,EAAI,EAAGA,EAAI8C,EAAElC,OAAQZ,IAC1B,GAAK8C,EAAG9C,KAAQwB,EACf,OAAO,EAITsB,EAAE7C,KAAMuB,EACR,CACD,OAAO,CACP,CAOD,SAASJ,IACR,IAAIpB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKe,OAAQZ,IAC7BH,EAAMG,GAAIY,OAAS,EAEpBH,EAAS,CACT,CACF,CEnTG,IAAC4C,EAAiB7C,ICPrBQ,EAAAsC,EAAA,UAAA9C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index c427859..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From cc435a98b4a29d5467031326f84ccefe8556589f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 31 Dec 2023 11:08:03 +0000 Subject: [PATCH 057/103] 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 | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.calloc.js | 246 - benchmark/benchmark.factory.js | 71 - benchmark/benchmark.js | 246 - benchmark/benchmark.length.complex128.js | 102 - benchmark/benchmark.length.complex64.js | 102 - benchmark/benchmark.length.float32.js | 102 - benchmark/benchmark.length.float64.js | 102 - benchmark/benchmark.length.int16.js | 102 - benchmark/benchmark.length.int32.js | 102 - benchmark/benchmark.length.int8.js | 102 - benchmark/benchmark.length.uint16.js | 102 - benchmark/benchmark.length.uint32.js | 102 - benchmark/benchmark.length.uint8.js | 102 - benchmark/benchmark.length.uint8c.js | 102 - benchmark/benchmark.malloc.js | 246 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 347 -- docs/types/test.ts | 193 - examples/index.js | 80 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/bytes_per_element.json | 13 - lib/defaults.js | 42 - lib/factory.js | 370 -- lib/index.js | 56 - lib/main.js | 63 - lib/pool.js | 44 - lib/validate.js | 66 - package.json | 97 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 2240 -------- test/test.js | 1797 ------ 62 files changed, 6206 insertions(+), 10638 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.calloc.js delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.complex128.js delete mode 100644 benchmark/benchmark.length.complex64.js delete mode 100644 benchmark/benchmark.length.float32.js delete mode 100644 benchmark/benchmark.length.float64.js delete mode 100644 benchmark/benchmark.length.int16.js delete mode 100644 benchmark/benchmark.length.int32.js delete mode 100644 benchmark/benchmark.length.int8.js delete mode 100644 benchmark/benchmark.length.uint16.js delete mode 100644 benchmark/benchmark.length.uint32.js delete mode 100644 benchmark/benchmark.length.uint8.js delete mode 100644 benchmark/benchmark.length.uint8c.js delete mode 100644 benchmark/benchmark.malloc.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/bytes_per_element.json delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/pool.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ea35f20..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/array/pool) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6f7c875..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/array/pool) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 37cfff8..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -493,7 +492,7 @@ console.log( 'nbytes: %d', typedarray.nbytes ); ## 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]. @@ -559,7 +558,7 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/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.calloc.js b/benchmark/benchmark.calloc.js deleted file mode 100644 index fd8f53d..0000000 --- a/benchmark/benchmark.calloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':calloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 58918bb..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = typedarray.factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:highWaterMark', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'highWaterMark': 0 - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.highWaterMark = i; - f = typedarray.factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 4310559..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.complex128.js b/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 12c6668..0000000 --- a/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex64.js b/benchmark/benchmark.length.complex64.js deleted file mode 100644 index ca2b45c..0000000 --- a/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float32.js b/benchmark/benchmark.length.float32.js deleted file mode 100644 index b3b4508..0000000 --- a/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float64.js b/benchmark/benchmark.length.float64.js deleted file mode 100644 index 5f0132d..0000000 --- a/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int16.js b/benchmark/benchmark.length.int16.js deleted file mode 100644 index 9f253cb..0000000 --- a/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int32.js b/benchmark/benchmark.length.int32.js deleted file mode 100644 index f83e795..0000000 --- a/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int8.js b/benchmark/benchmark.length.int8.js deleted file mode 100644 index 5b01174..0000000 --- a/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint16.js b/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 32b0a5d..0000000 --- a/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint32.js b/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 290b90c..0000000 --- a/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8.js b/benchmark/benchmark.length.uint8.js deleted file mode 100644 index ff7d733..0000000 --- a/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8c.js b/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index 8f0d10a..0000000 --- a/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.malloc.js b/benchmark/benchmark.malloc.js deleted file mode 100644 index 1661907..0000000 --- a/benchmark/benchmark.malloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':malloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 9689761..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/array/pool" -%% click B href "https://github.com/stdlib-js/array-pool/tree/main" -%% click C href "https://github.com/stdlib-js/array-pool/tree/production" -%% click D href "https://github.com/stdlib-js/array-pool/tree/esm" -%% click E href "https://github.com/stdlib-js/array-pool/tree/deno" -%% click F href "https://github.com/stdlib-js/array-pool/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/pool -[production-url]: https://github.com/stdlib-js/array-pool/tree/production -[deno-url]: https://github.com/stdlib-js/array-pool/tree/deno -[umd-url]: https://github.com/stdlib-js/array-pool/tree/umd -[esm-url]: https://github.com/stdlib-js/array-pool/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 5160b6f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import typedarraypool from '../docs/types/index'; -export = typedarraypool; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 9d31d69..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var l=function(n,i){return function(){return i||n((i={exports:{}}).exports,i),i.exports}};var k=l(function(kr,M){ -function D(){return{highWaterMark:9007199254740992}}M.exports=D -});var E=l(function(Ar,W){ -var G=require('@stdlib/assert-is-plain-object/dist'),H=require('@stdlib/assert-has-own-property/dist'),J=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,A=require('@stdlib/error-tools-fmtprodmsg/dist');function K(n,i){return G(i)?H(i,"highWaterMark")&&(n.highWaterMark=i.highWaterMark,!J(n.highWaterMark))?new TypeError(A('01H2t',"highWaterMark",n.highWaterMark)):null:new TypeError(A('01H2V',i));}W.exports=K -});var C=l(function(Wr,T){ -function Q(n){var i,u;for(i=[],u=0;uv.highWaterMark?null:(e=new ur(r),i+=r,e)}function d(r,e,t){var a;return e===0?new r(0):(a=_(lr(e)*hr[t]),a===null?a:new r(a,0,e))}function s(){var r,e,t,a,o,x,w,c,f;if(r=arguments.length,r&&X(arguments[r-1])?(r-=1,e=arguments[r]):e="float64",t=y(e),t===null)throw new TypeError(m('01H2Y',e));if(r<=0)return new t(0);if(Z(arguments[0]))return d(t,arguments[0],e);if($(arguments[0])){if(a=arguments[0],c=a.length,tr(a)?a=P(a,0):ar(a)?a=b(a,0):/^complex/.test(e)&&(c/=2),o=d(t,c,e),o===null)return o;if(L(o)||N(o))return o.set(a),o;for(w=B(nr(a)).accessors[0],x=B(e).accessors[1],f=0;f0){for(e=or(p(r.byteLength)),e=vr(u.length-1,e),t=u[e],a=0;a[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = accessors( adtype( arr ) ).accessors[ 0 ];\n\t\t\tset = accessors( dtype ).accessors[ 1 ];\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nmodule.exports = typedarraypool;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* var typedarraypool = require( '@stdlib/array-pool' );\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,cAAiB,gBAClB,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,eAAgB,IACzCD,EAAK,cAAgBC,EAAQ,cACxB,CAACJ,EAAsBG,EAAK,aAAc,GACvC,IAAI,UAAWF,EAAQ,2EAA4E,gBAAiBE,EAAK,aAAc,CAAE,EAG3I,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cA6BA,SAASC,EAAM,EAAI,CAClB,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAI,EAAE,EAAGA,IACrBD,EAAI,KAAM,CAAC,CAAE,EAEd,OAAOA,CACR,CAKAF,EAAO,QAAUC,IC3CjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,QAAW,EACX,QAAW,EACX,MAAS,EACT,MAAS,EACT,KAAQ,EACR,OAAU,EACV,OAAU,EACV,MAAS,EACT,OAAU,EACT,UAAa,EACb,WAAc,EAChB,ICZA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAe,QAAS,8BAA+B,EACvDC,GAAmB,QAAS,oCAAqC,EACjEC,GAAgB,QAAS,+BAAgC,EACzDC,GAAmB,QAAS,kCAAmC,EAC/DC,GAAoB,QAAS,mCAAoC,EACjEC,EAAc,QAAS,uDAAwD,EAC/EC,GAAsB,QAAS,uDAAwD,EACvFC,EAAQ,QAAS,2BAA4B,EAC7CC,EAAgB,QAAS,4CAA6C,EACtEC,EAAiB,QAAS,6CAA8C,EACxEC,EAAY,QAAS,8BAA+B,EACpDC,GAAS,QAAS,qBAAsB,EACxCC,EAAS,QAAS,uBAAwB,EAC1CC,GAAc,QAAS,sBAAuB,EAC9CC,GAAO,QAAS,gCAAiC,EACjDC,GAAQ,QAAS,iCAAkC,EACnDC,GAAQ,QAAS,iCAAkC,EACnDC,EAAO,QAAS,gCAAiC,EACjDC,GAAM,QAAS,+BAAgC,EAC/CC,GAAW,IACXC,GAAW,IACXC,GAAa,IACbC,GAAoB,IAKpBC,GAAiBhB,EAAO,WAAY,EACpCiB,GAAkBjB,EAAO,YAAa,EAY1C,SAASkB,EAAgBC,EAAM,CAC9B,OAASA,aAAeH,EACzB,CASA,SAASI,EAAiBD,EAAM,CAC/B,OAASA,aAAeF,EACzB,CA6BA,SAASI,GAASC,EAAU,CAC3B,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,EAAOb,GAAS,EACX,UAAU,SACdc,EAAMb,GAAUY,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAAF,EAAOV,GAAYP,GAAMG,EAAMe,EAAK,aAAc,CAAE,CAAE,EACtDF,EAAS,EAETzB,EAAa6B,EAAQ,SAAUA,CAAO,EACtC7B,EAAa6B,EAAQ,SAAUC,CAAO,EACtC9B,EAAa6B,EAAQ,OAAQE,CAAK,EAClC/B,EAAa6B,EAAQ,QAASG,CAAM,EACpChC,EAAa6B,EAAQ,gBAAiBF,EAAK,aAAc,EACzD1B,GAAqB4B,EAAQ,SAAUI,CAAS,EAEzCJ,EAQP,SAASI,GAAW,CACnB,OAAOR,CACR,CASA,SAASS,EAAaC,EAAI,CACzB,IAAIC,EACAC,EAMJ,OAHAA,EAAIzB,EAAMuB,CAAE,EAGPE,EAAIX,EAAK,QAAUA,EAAMW,CAAE,EAAE,OAC1BX,EAAMW,CAAE,EAAE,IAAI,EAGjBZ,EAAOU,EAAIR,EAAK,cACb,MAERS,EAAM,IAAI5B,GAAa2B,CAAE,EAGzBV,GAAUU,EAEHC,EACR,CAWA,SAASE,EAAYC,EAAMC,EAAKC,EAAQ,CACvC,IAAIL,EACJ,OAAKI,IAAQ,EACL,IAAID,EAAM,CAAE,GAEpBH,EAAMF,EAAavB,GAAO6B,CAAI,EAAEvB,GAAmBwB,CAAM,CAAE,EACtDL,IAAQ,KACLA,EAED,IAAIG,EAAMH,EAAK,EAAGI,CAAI,EAC9B,CAkBA,SAASX,GAAS,CACjB,IAAIa,EACAD,EACAF,EACAlB,EACAsB,EACAC,EACAC,EACAL,EACAH,EAUJ,GARAK,EAAQ,UAAU,OACbA,GAASjD,EAAU,UAAWiD,EAAM,CAAE,CAAE,GAC5CA,GAAS,EACTD,EAAQ,UAAWC,CAAM,GAEzBD,EAAQ,UAETF,EAAOrC,EAAOuC,CAAM,EACfF,IAAS,KACb,MAAM,IAAI,UAAWhC,EAAQ,sEAAuEkC,CAAM,CAAE,EAE7G,GAAKC,GAAS,EACb,OAAO,IAAIH,EAAM,CAAE,EAGpB,GAAK7C,EAAsB,UAAW,CAAE,CAAE,EACzC,OAAO4C,EAAYC,EAAM,UAAW,CAAE,EAAGE,CAAM,EAGhD,GAAK9C,EAAc,UAAW,CAAE,CAAE,EAAI,CAYrC,GAXA0B,EAAM,UAAW,CAAE,EACnBmB,EAAMnB,EAAI,OACLtB,GAAmBsB,CAAI,EAC3BA,EAAMjB,EAAgBiB,EAAK,CAAE,EAClBvB,GAAkBuB,CAAI,EACjCA,EAAMlB,EAAekB,EAAK,CAAE,EACjB,WAAW,KAAMoB,CAAM,IAElCD,GAAO,GAERG,EAAML,EAAYC,EAAMC,EAAKC,CAAM,EAC9BE,IAAQ,KACZ,OAAOA,EAER,GAAKrB,EAAiBqB,CAAI,GAAKvB,EAAgBuB,CAAI,EAClD,OAAAA,EAAI,IAAKtB,CAAI,EACNsB,EAKR,IAFAE,EAAMxC,EAAWC,GAAQe,CAAI,CAAE,EAAE,UAAW,CAAE,EAC9CuB,EAAMvC,EAAWoC,CAAM,EAAE,UAAW,CAAE,EAChCJ,EAAI,EAAGA,EAAIG,EAAKH,IACrBO,EAAKD,EAAKN,EAAGQ,EAAKxB,EAAKgB,CAAE,CAAE,EAE5B,OAAOM,CACR,CACA,MAAM,IAAI,UAAWpC,EAAQ,wGAAyG,UAAW,CAAE,CAAE,CAAE,CACxJ,CAgBA,SAASuB,GAAS,CACjB,IAAIY,EACAC,EACAG,EACAT,EAUJ,GARAK,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAMd,EAAO,EACFa,IAAU,EACrBC,EAAMd,EAAQ,UAAW,CAAE,CAAE,EAE7Bc,EAAMd,EAAQ,UAAW,CAAE,EAAG,UAAW,CAAE,CAAE,EAEzCc,IAAQ,KASZ,IAPKrB,EAAiBqB,CAAI,EACzBG,EAAM1C,EAAgBuC,EAAK,CAAE,EAClBvB,EAAgBuB,CAAI,EAC/BG,EAAM3C,EAAewC,EAAK,CAAE,EAE5BG,EAAMH,EAEDN,EAAI,EAAGA,EAAIS,EAAI,OAAQT,IAC5BS,EAAKT,CAAE,EAAI,EAGb,OAAOM,CACR,CAcA,SAASZ,EAAMK,EAAM,CACpB,IAAID,EACAY,EACAV,EACJ,GAAKzC,GAAkBwC,CAAI,GAAKA,EAAI,OACnCA,EAAMA,EAAI,eACC,CAACvC,GAAeuC,CAAI,EAC/B,MAAM,IAAI,UAAW7B,EAAQ,4EAA6E6B,CAAI,CAAE,EAEjH,GAAKA,EAAI,WAAa,EAAI,CAQzB,IAPAD,EAAIzB,GAAOE,EAAMwB,EAAI,UAAW,CAAE,EAGlCD,EAAItB,GAAKa,EAAK,OAAO,EAAGS,CAAE,EAG1BY,EAAIrB,EAAMS,CAAE,EACNE,EAAI,EAAGA,EAAIU,EAAE,OAAQV,IAC1B,GAAKU,EAAGV,CAAE,IAAMD,EACf,MAAO,GAITW,EAAE,KAAMX,CAAI,CACb,CACA,MAAO,EACR,CAOA,SAASJ,GAAQ,CAChB,IAAIK,EACJ,IAAMA,EAAI,EAAGA,EAAIX,EAAK,OAAQW,IAC7BX,EAAMW,CAAE,EAAE,OAAS,EAEpBZ,EAAS,CACV,CACD,CAKAjC,EAAO,QAAU+B,KCjXjB,IAAAyB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAU,IAmCVC,GAAiBD,GAAQ,EAK7BD,EAAO,QAAUE,KCnBjB,IAAIC,GAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,GAAU,IAKdF,GAAaC,EAAM,UAAWC,EAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isNonNegativeInteger", "format", "validate", "opts", "options", "require_pool", "__commonJSMin", "exports", "module", "pool", "out", "i", "require_bytes_per_element", "__commonJSMin", "exports", "module", "require_factory", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isCollection", "isTypedArrayLike", "isArrayBuffer", "isComplex64Array", "isComplex128Array", "setReadOnly", "setReadOnlyAccessor", "ctors", "reinterpret64", "reinterpret128", "accessors", "adtype", "format", "ArrayBuffer", "ceil", "floor", "ceil2", "log2", "min", "defaults", "validate", "createPool", "BYTES_PER_ELEMENT", "Complex64Array", "Complex128Array", "isCmplx64Array", "arr", "isCmplx128Array", "factory", "options", "nbytes", "pool", "opts", "err", "malloc", "calloc", "free", "clear", "getBytes", "arraybuffer", "n", "buf", "i", "typedarray", "ctor", "len", "dtype", "nargs", "out", "set", "get", "tmp", "p", "require_main", "__commonJSMin", "exports", "module", "factory", "typedarraypool", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5244595..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,347 +0,0 @@ - -{{alias}}( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - Memory is **uninitialized**, which means that the contents of a returned - typed array may contain sensitive contents. - - The function supports the following data types: - - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - The default typed array data type is `float64`. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}() - [] - > arr = {{alias}}( 'float32' ) - [] - - -{{alias}}( length[, dtype] ) - Returns an uninitialized typed array having a specified length from a typed - array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > arr = {{alias}}( 5, 'int32' ) - - - -{{alias}}( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - This method shares the same security vulnerabilities mentioned above. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc() - - > arr = {{alias}}.malloc( 'float32' ) - - - -{{alias}}.malloc( length[, dtype] ) - Returns a typed array having a specified length from a typed array memory - pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc( 5 ) - - > arr = {{alias}}.malloc( 5, 'int32' ) - - - -{{alias}}.malloc( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}.malloc( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.calloc( [dtype] ) - Returns a zero-initialized typed array from a typed array memory pool. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc() - [] - > arr = {{alias}}.calloc( 'float32' ) - [] - - -{{alias}}.calloc( length[, dtype] ) - Returns a zero-initialized typed array having a specified length from a - typed array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}.calloc( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}.free( buf ) - Frees a typed array or typed array buffer for use in a future allocation. - - Parameters - ---------- - buf: TypedArray|ArrayBuffer - Typed array or typed array buffer to free. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ) - - -{{alias}}.clear() - Clears the typed array pool allowing garbage collection of previously - allocated (and currently free) array buffers. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - > {{alias}}.clear() - - -{{alias}}.highWaterMark - Read-only property returning the pool's high water mark. - - Once a high water mark is reached, typed array allocation fails. - - Examples - -------- - > {{alias}}.highWaterMark - - -{{alias}}.nbytes - Read-only property returning the total number of allocated bytes. - - The returned value is the total accumulated value. Hence, anytime a pool - must allocate a new array buffer (i.e., more memory), the pool increments - this value. - - The only time this value is decremented is when a pool is cleared. - - This behavior means that, while allocated buffers which are never freed may, - in fact, be garbage collected, they continue to count against the high water - mark limit. - - Accordingly, you should *always* free allocated buffers in order to prevent - the pool from believing that non-freed buffers are continually in use. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.nbytes - - -{{alias}}.factory( [options] ) - Creates a typed array pool. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.highWaterMark: integer (optional) - Maximum total memory (in bytes) which can be allocated. - - Returns - ------- - fcn: Function - Function for creating typed arrays from a typed array memory pool. - - Examples - -------- - > var pool = {{alias}}.factory(); - > var arr1 = pool( 3, 'float64' ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 4336c42..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,193 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-empty */ -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import typedarraypool = require( './index' ); - - -// TESTS // - -// The function returns a typed array or null... -{ - typedarraypool(); // $ExpectType TypedArrayOrNull - typedarraypool( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the function is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool( true ); // $ExpectError - typedarraypool( false ); // $ExpectError - typedarraypool( null ); // $ExpectError - typedarraypool( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized data type... -{ - typedarraypool( 4, true ); // $ExpectError - typedarraypool( 4, false ); // $ExpectError - typedarraypool( 4, null ); // $ExpectError - typedarraypool( 4, 'abc' ); // $ExpectError - typedarraypool( 4, 123 ); // $ExpectError - typedarraypool( 4, [] ); // $ExpectError - typedarraypool( 4, {} ); // $ExpectError - typedarraypool( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an incorrect number of arguments... -{ - typedarraypool( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `malloc` method which returns a typed array or null... -{ - typedarraypool.malloc(); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.malloc( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `malloc` method is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool.malloc( true ); // $ExpectError - typedarraypool.malloc( false ); // $ExpectError - typedarraypool.malloc( null ); // $ExpectError - typedarraypool.malloc( {} ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.malloc( 4, true ); // $ExpectError - typedarraypool.malloc( 4, false ); // $ExpectError - typedarraypool.malloc( 4, null ); // $ExpectError - typedarraypool.malloc( 4, 'abc' ); // $ExpectError - typedarraypool.malloc( 4, 123 ); // $ExpectError - typedarraypool.malloc( 4, [] ); // $ExpectError - typedarraypool.malloc( 4, {} ); // $ExpectError - typedarraypool.malloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided an incorrect number of arguments... -{ - typedarraypool.malloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `calloc` method which returns a typed array or null... -{ - typedarraypool.calloc(); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `calloc` method is provided a first argument which is not a number... -{ - typedarraypool.calloc( 'abc' ); // $ExpectError - typedarraypool.calloc( true ); // $ExpectError - typedarraypool.calloc( false ); // $ExpectError - typedarraypool.calloc( null ); // $ExpectError - typedarraypool.calloc( {} ); // $ExpectError - typedarraypool.calloc( [] ); // $ExpectError - typedarraypool.calloc( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.calloc( 4, true ); // $ExpectError - typedarraypool.calloc( 4, false ); // $ExpectError - typedarraypool.calloc( 4, null ); // $ExpectError - typedarraypool.calloc( 4, 'abc' ); // $ExpectError - typedarraypool.calloc( 4, 123 ); // $ExpectError - typedarraypool.calloc( 4, [] ); // $ExpectError - typedarraypool.calloc( 4, {} ); // $ExpectError - typedarraypool.calloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided an incorrect number of arguments... -{ - typedarraypool.calloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `factory` method which returns a typed array pool.. -{ - typedarraypool.factory(); // $ExpectType Pool - typedarraypool.factory( { 'highWaterMark': 556 } ); // $ExpectType Pool -} - -// The compiler throws an error if the `factory` method is provided a `highWaterMark` option which is not a number... -{ - typedarraypool.factory( { 'highWaterMark': true } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': false } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': 'abc' } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': null } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': [] } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': {} } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an incorrect number of arguments... -{ - typedarraypool.factory( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` method which returns void... -{ - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.free( arr ); // $ExpectType void -} - -// The compiler throws an error if the `free` method is provided a first argument which is neither a typed array nor array buffer... -{ - typedarraypool.free( true ); // $ExpectError - typedarraypool.free( false ); // $ExpectError - typedarraypool.free( 123 ); // $ExpectError - typedarraypool.free( 'abc' ); // $ExpectError - typedarraypool.free( null ); // $ExpectError - typedarraypool.free( {} ); // $ExpectError - typedarraypool.free( ( x: number ): number => x ); // $ExpectError -} - -// Attached to the main export is a `clear` method which returns void... -{ - typedarraypool.clear(); // $ExpectType void -} - -// The compiler throws an error if the `clear` method is provided arguments... -{ - typedarraypool.clear( {} ); // $ExpectError - typedarraypool.clear( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `highWaterMark` property... -{ - typedarraypool.highWaterMark; // $ExpectType number -} - -// Attached to the main export is a `nbytes` property... -{ - typedarraypool.nbytes; // $ExpectType number -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 24a7846..0000000 --- a/examples/index.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 randu = require( '@stdlib/random-base-randu' ); -var typedarraypool = require( './../lib' ); - -// Create a typed array pool which can allocate at most 1GB: -var typedarray = typedarraypool.factory({ - 'highWaterMark': 1e9 -}); - -// Inspect the pool: -console.log( 'Max bytes: %d', typedarray.highWaterMark ); -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Allocate an array for storing double-precision floating-point numbers: -var arr1 = typedarray( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Fill the array... -var i; -for ( i = 0; i < arr1.length; i++ ) { - arr1[ i ] = randu(); -} - -// Inspect array contents: -console.log( arr1 ); - -// Free the array: -typedarray.free( arr1 ); - -// Allocate another array similar to the previous one: -var arr2 = typedarray( 5, 'float64' ); -// returns - -// Check that we have been returned a new typed array view: -console.log( arr2 === arr1 ); -// => false - -// Inspect array contents: -console.log( arr2 ); - -// Free the array: -typedarray.free( arr2 ); - -// Allocate an initialized array: -var arr3 = typedarray.calloc( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect array contents: -console.log( arr3 ); - -// Free the array: -typedarray.free( arr3 ); - -// Clear the pool: -typedarray.clear(); - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 4254ef5..0f5442f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike, RealOrComplexTypedArray, NumericDataType as DataType } from '@stdlib/types/array'; import ArrayBuffer = require( '@stdlib/array-buffer' ); diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..0125339 --- /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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessors@v0.1.0-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.1.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.1.0-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.1.1-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.1.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";function k(e,t){return y(t)?w(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(f("invalid option. `%s` option must be a nonnegative integer. Option: `%s`.","highWaterMark",e.highWaterMark)):null:new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",t))}function M(e){var t,r;for(t=[],r=0;rT.highWaterMark?null:(t=new j(e),w+=e,t)}function B(e,t,r){var s;return 0===t?new e(0):null===(s=A(g(t)*W[r]))?s:new e(s,0,t)}function F(){var e,n,i,m,j,v,u,g,b;if(n=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(i=l(n)))throw new TypeError(f("invalid argument. Must provide a recognized data type. Value: `%s`.",n));if(e<=0)return new i(0);if(r(arguments[0]))return B(i,arguments[0],n);if(s(arguments[0])){if(g=(m=arguments[0]).length,o(m)?m=h(m,0):a(m)?m=d(m,0):/^complex/.test(n)&&(g/=2),null===(j=B(i,g,n)))return j;if(L(j)||V(j))return j.set(m),j;for(u=p(c(m)).accessors[0],v=p(n).accessors[1],b=0;b0){for(t=u(b(e.byteLength)),t=x(E.length-1,t),r=E[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = accessors( adtype( arr ) ).accessors[ 0 ];\n\t\t\tset = accessors( dtype ).accessors[ 1 ];\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","accessors","adtype","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;gwEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,2EAA4E,gBAAiBP,EAAKI,gBAG3H,KARC,IAAIE,UAAWC,EAAQ,qEAAsEN,GAStG,CC/BA,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,iHCaIG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EC/EO,CACNI,cAAiB,kBD+EbkB,UAAUC,SACdF,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOgB,EAAYC,EAAMC,EAAM1B,EAAKI,iBACpCgB,EAAS,EAETO,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB5B,EAAKI,eAC3C4B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOb,CACP,CASD,SAASc,EAAazB,GACrB,IAAI0B,EACAxB,EAMJ,OAHAA,EAAIe,EAAMjB,IAGDD,EAAKe,QAAUf,EAAMG,GAAIY,OAC1Bf,EAAMG,GAAIyB,MAGbhB,EAAOX,EAAIT,EAAKI,cACb,MAER+B,EAAM,IAAIE,EAAa5B,GAGvBW,GAAUX,EAEH0B,EACP,CAWD,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,EACzB,CAkBD,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAtB,EACAP,EACAmC,EACAC,EACAN,EACA7B,EAUJ,GALC8B,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAOzB,EAAO2B,IAEb,MAAM,IAAInC,UAAWC,EAAQ,sEAAuEkC,IAErG,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKlC,EAAsBiB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAvB,EAAMK,UAAW,IACPC,OACL0B,EAAmBhC,GACvBA,EAAMiC,EAAgBjC,EAAK,GAChBkC,EAAkBlC,GAC7BA,EAAMmC,EAAenC,EAAK,GACf,WAAWoC,KAAMZ,KAE5BD,GAAO,GAGK,QADb9B,EAAM4B,EAAYC,EAAMC,EAAKC,IAE5B,OAAO/B,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAImC,IAAK5B,GACFP,EAKR,IAFAoC,EAAMQ,EAAWC,EAAQtC,IAAQqC,UAAW,GAC5CT,EAAMS,EAAWb,GAAQa,UAAW,GAC9B3C,EAAI,EAAGA,EAAI6B,EAAK7B,IACrBkC,EAAKnC,EAAKC,EAAGmC,EAAK7B,EAAKN,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,wGAAyGe,UAAW,IACjJ,CAgBD,SAASO,IACR,IAAIe,EACAlC,EACA8C,EACA7C,EAUJ,GAAa,QANZD,EADc,KADfkC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCkC,EADItC,EAAiBR,GACfwC,EAAgBxC,EAAK,GAChBM,EAAgBN,GACrB0C,EAAe1C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAI6C,EAAIjC,OAAQZ,IAC5B6C,EAAK7C,GAAM,EAGb,OAAOD,CACP,CAcD,SAASoB,EAAMK,GACd,IAAI1B,EACAgD,EACA9C,EACJ,GAAK+C,EAAkBvB,IAASA,EAAIwB,OACnCxB,EAAMA,EAAIwB,YACJ,IAAMC,EAAezB,GAC3B,MAAM,IAAI7B,UAAWC,EAAQ,4EAA6E4B,IAE3G,GAAKA,EAAI0B,WAAa,EAAI,CAQzB,IAPApD,EAAIqD,EAAOpC,EAAMS,EAAI0B,aAGrBpD,EAAIsD,EAAKvD,EAAKe,OAAO,EAAGd,GAGxBgD,EAAIjD,EAAMC,GACJE,EAAI,EAAGA,EAAI8C,EAAElC,OAAQZ,IAC1B,GAAK8C,EAAG9C,KAAQwB,EACf,OAAO,EAITsB,EAAE7C,KAAMuB,EACR,CACD,OAAO,CACP,CAOD,SAASJ,IACR,IAAIpB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKe,OAAQZ,IAC7BH,EAAMG,GAAIY,OAAS,EAEpBH,EAAS,CACT,CACF,CEnTG,IAAC4C,EAAiB7C,ICPrBQ,EAAAsC,EAAA,UAAA9C"} \ No newline at end of file diff --git a/lib/bytes_per_element.json b/lib/bytes_per_element.json deleted file mode 100644 index f97fe70..0000000 --- a/lib/bytes_per_element.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "float64": 8, - "float32": 4, - "int16": 2, - "int32": 4, - "int8": 1, - "uint16": 2, - "uint32": 4, - "uint8": 1, - "uint8c": 1, - "complex64": 8, - "complex128": 16 -} diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index a421711..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +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'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'highWaterMark': 9007199254740992 - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index edfecbe..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,370 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var isComplex64Array = require( '@stdlib/assert-is-complex64array' ); -var isComplex128Array = require( '@stdlib/assert-is-complex128array' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var ctors = require( '@stdlib/array-typed-ctors' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var accessors = require( '@stdlib/array-base-accessors' ); -var adtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/string-format' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil = require( '@stdlib/math-base-special-ceil' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); -var log2 = require( '@stdlib/math-base-special-log2' ); -var min = require( '@stdlib/math-base-special-min' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var createPool = require( './pool.js' ); -var BYTES_PER_ELEMENT = require( './bytes_per_element.json' ); - - -// VARIABLES // - -var Complex64Array = ctors( 'complex64' ); -var Complex128Array = ctors( 'complex128' ); - - -// FUNCTIONS // - -/** -* Tests whether an array is a single-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a single-precision complex floating-point number array -*/ -function isCmplx64Array( arr ) { - return ( arr instanceof Complex64Array ); -} - -/** -* Tests whether an array is a double-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a double-precision complex floating-point number array -*/ -function isCmplx128Array( arr ) { - return ( arr instanceof Complex128Array ); -} - - -// MAIN // - -/** -* Creates a typed array pool. -* -* @param {Options} [options] - pool options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} allocator -* -* @example -* var typedarraypool = factory(); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -function factory( options ) { - var nbytes; - var pool; - var opts; - var err; - - opts = defaults(); - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - pool = createPool( ceil( log2( opts.highWaterMark ) ) ); - nbytes = 0; - - setReadOnly( malloc, 'malloc', malloc ); // circular reference - setReadOnly( malloc, 'calloc', calloc ); - setReadOnly( malloc, 'free', free ); - setReadOnly( malloc, 'clear', clear ); - setReadOnly( malloc, 'highWaterMark', opts.highWaterMark ); - setReadOnlyAccessor( malloc, 'nbytes', getBytes ); - - return malloc; - - /** - * Returns the number of allocated bytes. - * - * @private - * @returns {NonNegativeInteger} number of allocated bytes - */ - function getBytes() { - return nbytes; - } - - /** - * Returns an array buffer. - * - * @private - * @param {NonNegativeInteger} n - number of bytes - * @returns {(ArrayBuffer|null)} array buffer or null - */ - function arraybuffer( n ) { - var buf; - var i; - - // Convert the number of bytes to an index in our pool table: - i = log2( n ); - - // If we already have an available array buffer, use it... - if ( i < pool.length && pool[ i ].length ) { - return pool[ i ].pop(); - } - // Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate... - if ( nbytes+n > opts.highWaterMark ) { - return null; - } - buf = new ArrayBuffer( n ); - - // Update the running counter of allocated bytes: - nbytes += n; - - return buf; - } - - /** - * Returns a typed array. - * - * @private - * @param {Function} ctor - typed array constructor - * @param {NonNegativeInteger} len - view length - * @param {string} dtype - data type - * @returns {(TypedArray|null)} typed array or null - */ - function typedarray( ctor, len, dtype ) { - var buf; - if ( len === 0 ) { - return new ctor( 0 ); - } - buf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] ); - if ( buf === null ) { - return buf; - } - return new ctor( buf, 0, len ); - } - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length or an array-like object - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function malloc() { - var nargs; - var dtype; - var ctor; - var arr; - var out; - var set; - var get; - var len; - var i; - - nargs = arguments.length; - if ( nargs && isString( arguments[ nargs-1 ] ) ) { - nargs -= 1; - dtype = arguments[ nargs ]; - } else { - dtype = 'float64'; - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) ); - } - if ( nargs <= 0 ) { - return new ctor( 0 ); - } - // Check if provided a typed array length... - if ( isNonNegativeInteger( arguments[ 0 ] ) ) { - return typedarray( ctor, arguments[ 0 ], dtype ); - } - // Check if provided an array-like object containing data elements... - if ( isCollection( arguments[ 0 ] ) ) { - arr = arguments[ 0 ]; - len = arr.length; - if ( isComplex128Array( arr ) ) { - arr = reinterpret128( arr, 0 ); - } else if ( isComplex64Array( arr ) ) { - arr = reinterpret64( arr, 0 ); - } else if ( /^complex/.test( dtype ) ) { - // Assume we've been provided an array of interleaved real and imaginary components... - len /= 2; - } - out = typedarray( ctor, len, dtype ); - if ( out === null ) { - return out; - } - if ( isCmplx128Array( out ) || isCmplx64Array( out ) ) { - out.set( arr ); - return out; - } - // Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other "unsafe" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things... - get = accessors( adtype( arr ) ).accessors[ 0 ]; - set = accessors( dtype ).accessors[ 1 ]; - for ( i = 0; i < len; i++ ) { - set( out, i, get( arr, i ) ); - } - return out; - } - throw new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) ); - } - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {NonNegativeInteger} [len=0] - array length - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function calloc() { - var nargs; - var out; - var tmp; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - out = malloc(); - } else if ( nargs === 1 ) { - out = malloc( arguments[ 0 ] ); - } else { - out = malloc( arguments[ 0 ], arguments[ 1 ] ); - } - if ( out !== null ) { - // Initialize the memory... - if ( isCmplx128Array( out ) ) { - tmp = reinterpret128( out, 0 ); - } else if ( isCmplx64Array( out ) ) { - tmp = reinterpret64( out, 0 ); - } else { - tmp = out; - } - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = 0.0; - } - } - return out; - } - - /** - * Frees a typed array or typed array buffer. - * - * ## Notes - * - * - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., "freeing" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool. - * - * @private - * @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free - * @throws {TypeError} must provide a typed array or typed array buffer - * @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed - */ - function free( buf ) { - var n; - var p; - var i; - if ( isTypedArrayLike( buf ) && buf.buffer ) { - buf = buf.buffer; - } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) ); - } - if ( buf.byteLength > 0 ) { - n = floor( log2( buf.byteLength ) ); - - // Prohibit "freeing" array buffers which would potentially allow users to circumvent high water mark limits: - n = min( pool.length-1, n ); - - // Ensure that we do not attempt to free the same buffer more than once... - p = pool[ n ]; - for ( i = 0; i < p.length; i++ ) { - if ( p[ i ] === buf ) { - return false; - } - } - // Add the buffer to our pool of free buffers: - p.push( buf ); - } - return true; - } - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @private - */ - function clear() { - var i; - for ( i = 0; i < pool.length; i++ ) { - pool[ i ].length = 0; - } - nbytes = 0; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6c12a4e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Typed array pool. -* -* @module @stdlib/array-pool -* -* @example -* var typedarraypool = require( '@stdlib/array-pool' ); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8f69ee3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,63 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @name typedarraypool -* @type {Function} -* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a valid array length or an array-like object -* @throws {TypeError} must provide a recognized data type -* @returns {(TypedArray|null)} typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -var typedarraypool = factory(); - - -// EXPORTS // - -module.exports = typedarraypool; diff --git a/lib/pool.js b/lib/pool.js deleted file mode 100644 index 5abd287..0000000 --- a/lib/pool.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Initializes a cache for pooled typed array buffers. -* -* @private -* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size -* @returns {ArrayArray} initialized cache -*/ -function pool( n ) { - var out; - var i; - - out = []; - for ( i = 0; i < n+1; i++ ) { - out.push( [] ); - } - return out; -} - - -// EXPORTS // - -module.exports = pool; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index ce54890..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'highWaterMark': 1024 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'highWaterMark' ) ) { - opts.highWaterMark = options.highWaterMark; - if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 9a6418f..bd7b179 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Typed array pool.", "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,76 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessors": "^0.1.0", - "@stdlib/array-buffer": "^0.1.0", - "@stdlib/array-dtype": "^0.1.0", - "@stdlib/array-typed-ctors": "^0.1.0", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-arraybuffer": "^0.1.1", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-complex128array": "^0.1.0", - "@stdlib/assert-is-complex64array": "^0.1.0", - "@stdlib/assert-is-nonnegative-integer": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/assert-is-string": "^0.1.1", - "@stdlib/assert-is-typed-array-like": "^0.1.0", - "@stdlib/math-base-special-ceil": "^0.1.1", - "@stdlib/math-base-special-ceil2": "^0.1.0", - "@stdlib/math-base-special-floor": "^0.1.1", - "@stdlib/math-base-special-log2": "^0.1.1", - "@stdlib/math-base-special-min": "^0.1.1", - "@stdlib/strided-base-reinterpret-complex128": "^0.1.1", - "@stdlib/strided-base-reinterpret-complex64": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.1.0", - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-float32": "^0.1.1", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/array-int16": "^0.1.1", - "@stdlib/array-int32": "^0.1.1", - "@stdlib/array-int8": "^0.1.1", - "@stdlib/array-uint16": "^0.1.1", - "@stdlib/array-uint32": "^0.1.1", - "@stdlib/array-uint8": "^0.1.1", - "@stdlib/array-uint8c": "^0.1.1", - "@stdlib/assert-instance-of": "^0.1.1", - "@stdlib/assert-is-complex-typed-array": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-typed-array": "^0.1.0", - "@stdlib/complex-float32": "^0.1.1", - "@stdlib/complex-float64": "^0.1.1", - "@stdlib/complex-imag": "^0.1.1", - "@stdlib/complex-imagf": "^0.1.1", - "@stdlib/complex-real": "^0.1.1", - "@stdlib/complex-realf": "^0.1.1", - "@stdlib/math-base-special-pow": "^0.1.0", - "@stdlib/random-base-randu": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e230764 --- /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.factory.js b/test/test.factory.js deleted file mode 100644 index 396aee2..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,2240 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function (no options)', function test( t ) { - t.strictEqual( typeof factory(), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - t.strictEqual( typeof factory( {} ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided a `highWaterMark` option which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (length)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a function which returns a typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, length)', function test( t ) { - var typedarraypool = factory(); - var arr; - - arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a `malloc` method which is a circular reference', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - var buf; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the returned function is a property which returns the pool\'s high water mark', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function supports specifying a high water mark which limits the total amount of memory a pool can allocate', function test( t ) { - var typedarraypool; - var arr1; - var arr2; - - typedarraypool = factory({ - 'highWaterMark': 64 // bytes - }); - - typedarraypool.clear(); - - arr1 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr1.length, 8, 'returns expected value' ); - t.strictEqual( arr1.byteLength, 64, 'returns expected value' ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - typedarraypool.free( arr1 ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Create an array which is less than or equal to the high water mark: - arr2 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr2.length, 8, 'returns expected value' ); - t.strictEqual( arr2.byteLength, 64, 'returns expected value' ); - - typedarraypool.free( arr2 ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a property which returns the total number of accumulated bytes', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var typedarraypool; - var arrs; - var i; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 54aa5ee..0000000 --- a/test/test.js +++ /dev/null @@ -1,1797 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var typedarraypool = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -}); From 218af5f66a1a4d6e055f57f626c17b71484dbfd1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 08:35:47 +0000 Subject: [PATCH 058/103] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e61dcc2..9a6418f 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "@stdlib/math-base-special-min": "^0.1.1", "@stdlib/strided-base-reinterpret-complex128": "^0.1.1", "@stdlib/strided-base-reinterpret-complex64": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From 21a528da696a8e60c0d5e6d9207123c458c132d9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 15:10:30 +0000 Subject: [PATCH 059/103] Remove files --- index.d.ts | 359 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6541 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 0f5442f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,359 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike, RealOrComplexTypedArray, NumericDataType as DataType } from '@stdlib/types/array'; -import ArrayBuffer = require( '@stdlib/array-buffer' ); - -/** -* Typed array or null. -*/ -type TypedArrayOrNull = RealOrComplexTypedArray | null; - -/** -* Interface defining pool options. -*/ -interface Options { - /** - * Maximum total memory which can be allocated. - */ - highWaterMark?: number; -} - -/** -* Pool interface. -*/ -interface Pool { - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr = typedarraypool(); - * // returns [] - * - * @example - * var arr = typedarraypool( 'float32' ); - * // returns [] - */ - ( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * // Allocate an array of doubles: - * var arr = typedarraypool( 5, 'float64' ); - * // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * typedarraypool.free( arr ); - * - * @example - * var arr1 = typedarraypool( [ 0.5, 0.5, 0.5 ] ); - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * @example - * var arr1 = [ 0.5, 0.5, 0.5 ]; - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - */ - ( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc(); - * // returns [] - * - * var arr2 = typedarraypool.calloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param length - typed array length - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc( 5 ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * var arr2 = typedarraypool.calloc( 5, 'uint8' ); - * // returns [ 0, 0, 0, 0, 0 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( length: number, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc(); - * // returns [] - * - * var arr2 = typedarraypool.malloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc( 5 ); - * // returns - * - * var arr2 = typedarraypool.malloc( 5, 'uint8' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 5.0, -3.0, 2.0 ] ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr2 = typedarraypool.malloc( arr1 ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr3 = typedarraypool.malloc( arr1, 'int32' ); - * // returns [ 5, -3, 2 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * typedarraypool.free( arr3 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ] ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * var arr2 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ], 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Frees a typed array or typed array buffer for use in a future allocation. - * - * @param buf - typed array or typed array buffer to free - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array for use in a future allocation: - * typedarraypool.free( arr ); - * - * // Create another typed array: - * arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array buffer for use in a future allocation: - * typedarraypool.free( arr.buffer ); - */ - free( buf: RealOrComplexTypedArray | ArrayBuffer ): void; - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr ); - * - * // ... - * - * // Clear all freed buffers: - * typedarraypool.clear(); - */ - clear(): void; - - /** - * Read-only property returning the pool's high water mark. - * - * ## Notes - * - * - Once a high water mark is reached, typed array allocation fails. - * - * @example - * var limit = typedarraypool.highWaterMark; - * // returns - */ - readonly highWaterMark: number; - - /** - * Read-only property returning the total number of allocated bytes. - * - * @example - * var arr = typedarraypool( 5, 'float64' ); - * - * var nbytes = typedarraypool.nbytes; - * // returns - */ - readonly nbytes: number; - - /** - * Creates a typed array pool. - * - * @param options - pool options - * @param options.highWaterMark - maximum total memory which can be allocated - * @throws must provide valid options - * @returns allocator - * - * @example - * var allocator = typedarraypool.factory(); - * - * // Allocate an array of doubles: - * var arr = allocator( 5, 'float64' ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * allocator.free( arr ); - */ - factory( options?: Options ): Pool; -} - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @param arg - an array length or an array-like object -* @param dtype - data type (default: 'float64') -* @returns typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -declare var typedarraypool: Pool; - - -// EXPORTS // - -export = typedarraypool; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 0125339..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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessors@v0.1.0-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.1.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.1.0-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.1.1-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.1.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";function k(e,t){return y(t)?w(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(f("invalid option. `%s` option must be a nonnegative integer. Option: `%s`.","highWaterMark",e.highWaterMark)):null:new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",t))}function M(e){var t,r;for(t=[],r=0;rT.highWaterMark?null:(t=new j(e),w+=e,t)}function B(e,t,r){var s;return 0===t?new e(0):null===(s=A(g(t)*W[r]))?s:new e(s,0,t)}function F(){var e,n,i,m,j,v,u,g,b;if(n=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(i=l(n)))throw new TypeError(f("invalid argument. Must provide a recognized data type. Value: `%s`.",n));if(e<=0)return new i(0);if(r(arguments[0]))return B(i,arguments[0],n);if(s(arguments[0])){if(g=(m=arguments[0]).length,o(m)?m=h(m,0):a(m)?m=d(m,0):/^complex/.test(n)&&(g/=2),null===(j=B(i,g,n)))return j;if(L(j)||V(j))return j.set(m),j;for(u=p(c(m)).accessors[0],v=p(n).accessors[1],b=0;b0){for(t=u(b(e.byteLength)),t=x(E.length-1,t),r=E[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = accessors( adtype( arr ) ).accessors[ 0 ];\n\t\t\tset = accessors( dtype ).accessors[ 1 ];\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","accessors","adtype","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;gwEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,2EAA4E,gBAAiBP,EAAKI,gBAG3H,KARC,IAAIE,UAAWC,EAAQ,qEAAsEN,GAStG,CC/BA,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,iHCaIG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EC/EO,CACNI,cAAiB,kBD+EbkB,UAAUC,SACdF,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOgB,EAAYC,EAAMC,EAAM1B,EAAKI,iBACpCgB,EAAS,EAETO,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB5B,EAAKI,eAC3C4B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOb,CACP,CASD,SAASc,EAAazB,GACrB,IAAI0B,EACAxB,EAMJ,OAHAA,EAAIe,EAAMjB,IAGDD,EAAKe,QAAUf,EAAMG,GAAIY,OAC1Bf,EAAMG,GAAIyB,MAGbhB,EAAOX,EAAIT,EAAKI,cACb,MAER+B,EAAM,IAAIE,EAAa5B,GAGvBW,GAAUX,EAEH0B,EACP,CAWD,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,EACzB,CAkBD,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAtB,EACAP,EACAmC,EACAC,EACAN,EACA7B,EAUJ,GALC8B,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAOzB,EAAO2B,IAEb,MAAM,IAAInC,UAAWC,EAAQ,sEAAuEkC,IAErG,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKlC,EAAsBiB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAvB,EAAMK,UAAW,IACPC,OACL0B,EAAmBhC,GACvBA,EAAMiC,EAAgBjC,EAAK,GAChBkC,EAAkBlC,GAC7BA,EAAMmC,EAAenC,EAAK,GACf,WAAWoC,KAAMZ,KAE5BD,GAAO,GAGK,QADb9B,EAAM4B,EAAYC,EAAMC,EAAKC,IAE5B,OAAO/B,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAImC,IAAK5B,GACFP,EAKR,IAFAoC,EAAMQ,EAAWC,EAAQtC,IAAQqC,UAAW,GAC5CT,EAAMS,EAAWb,GAAQa,UAAW,GAC9B3C,EAAI,EAAGA,EAAI6B,EAAK7B,IACrBkC,EAAKnC,EAAKC,EAAGmC,EAAK7B,EAAKN,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,wGAAyGe,UAAW,IACjJ,CAgBD,SAASO,IACR,IAAIe,EACAlC,EACA8C,EACA7C,EAUJ,GAAa,QANZD,EADc,KADfkC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCkC,EADItC,EAAiBR,GACfwC,EAAgBxC,EAAK,GAChBM,EAAgBN,GACrB0C,EAAe1C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAI6C,EAAIjC,OAAQZ,IAC5B6C,EAAK7C,GAAM,EAGb,OAAOD,CACP,CAcD,SAASoB,EAAMK,GACd,IAAI1B,EACAgD,EACA9C,EACJ,GAAK+C,EAAkBvB,IAASA,EAAIwB,OACnCxB,EAAMA,EAAIwB,YACJ,IAAMC,EAAezB,GAC3B,MAAM,IAAI7B,UAAWC,EAAQ,4EAA6E4B,IAE3G,GAAKA,EAAI0B,WAAa,EAAI,CAQzB,IAPApD,EAAIqD,EAAOpC,EAAMS,EAAI0B,aAGrBpD,EAAIsD,EAAKvD,EAAKe,OAAO,EAAGd,GAGxBgD,EAAIjD,EAAMC,GACJE,EAAI,EAAGA,EAAI8C,EAAElC,OAAQZ,IAC1B,GAAK8C,EAAG9C,KAAQwB,EACf,OAAO,EAITsB,EAAE7C,KAAMuB,EACR,CACD,OAAO,CACP,CAOD,SAASJ,IACR,IAAIpB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKe,OAAQZ,IAC7BH,EAAMG,GAAIY,OAAS,EAEpBH,EAAS,CACT,CACF,CEnTG,IAAC4C,EAAiB7C,ICPrBQ,EAAAsC,EAAA,UAAA9C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e230764..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 7eb325ae5026e69f96266cbbe3e0b7199e802133 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 15:11:14 +0000 Subject: [PATCH 060/103] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.calloc.js | 246 - benchmark/benchmark.factory.js | 71 - benchmark/benchmark.js | 246 - benchmark/benchmark.length.complex128.js | 102 - benchmark/benchmark.length.complex64.js | 102 - benchmark/benchmark.length.float32.js | 102 - benchmark/benchmark.length.float64.js | 102 - benchmark/benchmark.length.int16.js | 102 - benchmark/benchmark.length.int32.js | 102 - benchmark/benchmark.length.int8.js | 102 - benchmark/benchmark.length.uint16.js | 102 - benchmark/benchmark.length.uint32.js | 102 - benchmark/benchmark.length.uint8.js | 102 - benchmark/benchmark.length.uint8c.js | 102 - benchmark/benchmark.malloc.js | 246 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 347 -- docs/types/test.ts | 193 - examples/index.js | 80 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/bytes_per_element.json | 13 - lib/defaults.js | 42 - lib/factory.js | 370 -- lib/index.js | 56 - lib/main.js | 63 - lib/pool.js | 44 - lib/validate.js | 66 - package.json | 97 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 2240 -------- test/test.js | 1797 ------ 63 files changed, 6206 insertions(+), 10639 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.calloc.js delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.complex128.js delete mode 100644 benchmark/benchmark.length.complex64.js delete mode 100644 benchmark/benchmark.length.float32.js delete mode 100644 benchmark/benchmark.length.float64.js delete mode 100644 benchmark/benchmark.length.int16.js delete mode 100644 benchmark/benchmark.length.int32.js delete mode 100644 benchmark/benchmark.length.int8.js delete mode 100644 benchmark/benchmark.length.uint16.js delete mode 100644 benchmark/benchmark.length.uint32.js delete mode 100644 benchmark/benchmark.length.uint8.js delete mode 100644 benchmark/benchmark.length.uint8c.js delete mode 100644 benchmark/benchmark.malloc.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/bytes_per_element.json delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/pool.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 7f820a7..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-01-01T05:33:05.479Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ea35f20..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/array/pool) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6f7c875..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/array/pool) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 37cfff8..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -493,7 +492,7 @@ console.log( 'nbytes: %d', typedarray.nbytes ); ## 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]. @@ -559,7 +558,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/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.calloc.js b/benchmark/benchmark.calloc.js deleted file mode 100644 index fd8f53d..0000000 --- a/benchmark/benchmark.calloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':calloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 58918bb..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = typedarray.factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:highWaterMark', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'highWaterMark': 0 - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.highWaterMark = i; - f = typedarray.factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 4310559..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.complex128.js b/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 12c6668..0000000 --- a/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex64.js b/benchmark/benchmark.length.complex64.js deleted file mode 100644 index ca2b45c..0000000 --- a/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float32.js b/benchmark/benchmark.length.float32.js deleted file mode 100644 index b3b4508..0000000 --- a/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float64.js b/benchmark/benchmark.length.float64.js deleted file mode 100644 index 5f0132d..0000000 --- a/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int16.js b/benchmark/benchmark.length.int16.js deleted file mode 100644 index 9f253cb..0000000 --- a/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int32.js b/benchmark/benchmark.length.int32.js deleted file mode 100644 index f83e795..0000000 --- a/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int8.js b/benchmark/benchmark.length.int8.js deleted file mode 100644 index 5b01174..0000000 --- a/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint16.js b/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 32b0a5d..0000000 --- a/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint32.js b/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 290b90c..0000000 --- a/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8.js b/benchmark/benchmark.length.uint8.js deleted file mode 100644 index ff7d733..0000000 --- a/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8c.js b/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index 8f0d10a..0000000 --- a/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.malloc.js b/benchmark/benchmark.malloc.js deleted file mode 100644 index 1661907..0000000 --- a/benchmark/benchmark.malloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':malloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 9689761..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/array/pool" -%% click B href "https://github.com/stdlib-js/array-pool/tree/main" -%% click C href "https://github.com/stdlib-js/array-pool/tree/production" -%% click D href "https://github.com/stdlib-js/array-pool/tree/esm" -%% click E href "https://github.com/stdlib-js/array-pool/tree/deno" -%% click F href "https://github.com/stdlib-js/array-pool/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/pool -[production-url]: https://github.com/stdlib-js/array-pool/tree/production -[deno-url]: https://github.com/stdlib-js/array-pool/tree/deno -[umd-url]: https://github.com/stdlib-js/array-pool/tree/umd -[esm-url]: https://github.com/stdlib-js/array-pool/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 5160b6f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import typedarraypool from '../docs/types/index'; -export = typedarraypool; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 9d31d69..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var l=function(n,i){return function(){return i||n((i={exports:{}}).exports,i),i.exports}};var k=l(function(kr,M){ -function D(){return{highWaterMark:9007199254740992}}M.exports=D -});var E=l(function(Ar,W){ -var G=require('@stdlib/assert-is-plain-object/dist'),H=require('@stdlib/assert-has-own-property/dist'),J=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,A=require('@stdlib/error-tools-fmtprodmsg/dist');function K(n,i){return G(i)?H(i,"highWaterMark")&&(n.highWaterMark=i.highWaterMark,!J(n.highWaterMark))?new TypeError(A('01H2t',"highWaterMark",n.highWaterMark)):null:new TypeError(A('01H2V',i));}W.exports=K -});var C=l(function(Wr,T){ -function Q(n){var i,u;for(i=[],u=0;uv.highWaterMark?null:(e=new ur(r),i+=r,e)}function d(r,e,t){var a;return e===0?new r(0):(a=_(lr(e)*hr[t]),a===null?a:new r(a,0,e))}function s(){var r,e,t,a,o,x,w,c,f;if(r=arguments.length,r&&X(arguments[r-1])?(r-=1,e=arguments[r]):e="float64",t=y(e),t===null)throw new TypeError(m('01H2Y',e));if(r<=0)return new t(0);if(Z(arguments[0]))return d(t,arguments[0],e);if($(arguments[0])){if(a=arguments[0],c=a.length,tr(a)?a=P(a,0):ar(a)?a=b(a,0):/^complex/.test(e)&&(c/=2),o=d(t,c,e),o===null)return o;if(L(o)||N(o))return o.set(a),o;for(w=B(nr(a)).accessors[0],x=B(e).accessors[1],f=0;f0){for(e=or(p(r.byteLength)),e=vr(u.length-1,e),t=u[e],a=0;a[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = accessors( adtype( arr ) ).accessors[ 0 ];\n\t\t\tset = accessors( dtype ).accessors[ 1 ];\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nmodule.exports = typedarraypool;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* var typedarraypool = require( '@stdlib/array-pool' );\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,cAAiB,gBAClB,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,eAAgB,IACzCD,EAAK,cAAgBC,EAAQ,cACxB,CAACJ,EAAsBG,EAAK,aAAc,GACvC,IAAI,UAAWF,EAAQ,2EAA4E,gBAAiBE,EAAK,aAAc,CAAE,EAG3I,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cA6BA,SAASC,EAAM,EAAI,CAClB,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAI,EAAE,EAAGA,IACrBD,EAAI,KAAM,CAAC,CAAE,EAEd,OAAOA,CACR,CAKAF,EAAO,QAAUC,IC3CjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,QAAW,EACX,QAAW,EACX,MAAS,EACT,MAAS,EACT,KAAQ,EACR,OAAU,EACV,OAAU,EACV,MAAS,EACT,OAAU,EACT,UAAa,EACb,WAAc,EAChB,ICZA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAe,QAAS,8BAA+B,EACvDC,GAAmB,QAAS,oCAAqC,EACjEC,GAAgB,QAAS,+BAAgC,EACzDC,GAAmB,QAAS,kCAAmC,EAC/DC,GAAoB,QAAS,mCAAoC,EACjEC,EAAc,QAAS,uDAAwD,EAC/EC,GAAsB,QAAS,uDAAwD,EACvFC,EAAQ,QAAS,2BAA4B,EAC7CC,EAAgB,QAAS,4CAA6C,EACtEC,EAAiB,QAAS,6CAA8C,EACxEC,EAAY,QAAS,8BAA+B,EACpDC,GAAS,QAAS,qBAAsB,EACxCC,EAAS,QAAS,uBAAwB,EAC1CC,GAAc,QAAS,sBAAuB,EAC9CC,GAAO,QAAS,gCAAiC,EACjDC,GAAQ,QAAS,iCAAkC,EACnDC,GAAQ,QAAS,iCAAkC,EACnDC,EAAO,QAAS,gCAAiC,EACjDC,GAAM,QAAS,+BAAgC,EAC/CC,GAAW,IACXC,GAAW,IACXC,GAAa,IACbC,GAAoB,IAKpBC,GAAiBhB,EAAO,WAAY,EACpCiB,GAAkBjB,EAAO,YAAa,EAY1C,SAASkB,EAAgBC,EAAM,CAC9B,OAASA,aAAeH,EACzB,CASA,SAASI,EAAiBD,EAAM,CAC/B,OAASA,aAAeF,EACzB,CA6BA,SAASI,GAASC,EAAU,CAC3B,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,EAAOb,GAAS,EACX,UAAU,SACdc,EAAMb,GAAUY,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAAF,EAAOV,GAAYP,GAAMG,EAAMe,EAAK,aAAc,CAAE,CAAE,EACtDF,EAAS,EAETzB,EAAa6B,EAAQ,SAAUA,CAAO,EACtC7B,EAAa6B,EAAQ,SAAUC,CAAO,EACtC9B,EAAa6B,EAAQ,OAAQE,CAAK,EAClC/B,EAAa6B,EAAQ,QAASG,CAAM,EACpChC,EAAa6B,EAAQ,gBAAiBF,EAAK,aAAc,EACzD1B,GAAqB4B,EAAQ,SAAUI,CAAS,EAEzCJ,EAQP,SAASI,GAAW,CACnB,OAAOR,CACR,CASA,SAASS,EAAaC,EAAI,CACzB,IAAIC,EACAC,EAMJ,OAHAA,EAAIzB,EAAMuB,CAAE,EAGPE,EAAIX,EAAK,QAAUA,EAAMW,CAAE,EAAE,OAC1BX,EAAMW,CAAE,EAAE,IAAI,EAGjBZ,EAAOU,EAAIR,EAAK,cACb,MAERS,EAAM,IAAI5B,GAAa2B,CAAE,EAGzBV,GAAUU,EAEHC,EACR,CAWA,SAASE,EAAYC,EAAMC,EAAKC,EAAQ,CACvC,IAAIL,EACJ,OAAKI,IAAQ,EACL,IAAID,EAAM,CAAE,GAEpBH,EAAMF,EAAavB,GAAO6B,CAAI,EAAEvB,GAAmBwB,CAAM,CAAE,EACtDL,IAAQ,KACLA,EAED,IAAIG,EAAMH,EAAK,EAAGI,CAAI,EAC9B,CAkBA,SAASX,GAAS,CACjB,IAAIa,EACAD,EACAF,EACAlB,EACAsB,EACAC,EACAC,EACAL,EACAH,EAUJ,GARAK,EAAQ,UAAU,OACbA,GAASjD,EAAU,UAAWiD,EAAM,CAAE,CAAE,GAC5CA,GAAS,EACTD,EAAQ,UAAWC,CAAM,GAEzBD,EAAQ,UAETF,EAAOrC,EAAOuC,CAAM,EACfF,IAAS,KACb,MAAM,IAAI,UAAWhC,EAAQ,sEAAuEkC,CAAM,CAAE,EAE7G,GAAKC,GAAS,EACb,OAAO,IAAIH,EAAM,CAAE,EAGpB,GAAK7C,EAAsB,UAAW,CAAE,CAAE,EACzC,OAAO4C,EAAYC,EAAM,UAAW,CAAE,EAAGE,CAAM,EAGhD,GAAK9C,EAAc,UAAW,CAAE,CAAE,EAAI,CAYrC,GAXA0B,EAAM,UAAW,CAAE,EACnBmB,EAAMnB,EAAI,OACLtB,GAAmBsB,CAAI,EAC3BA,EAAMjB,EAAgBiB,EAAK,CAAE,EAClBvB,GAAkBuB,CAAI,EACjCA,EAAMlB,EAAekB,EAAK,CAAE,EACjB,WAAW,KAAMoB,CAAM,IAElCD,GAAO,GAERG,EAAML,EAAYC,EAAMC,EAAKC,CAAM,EAC9BE,IAAQ,KACZ,OAAOA,EAER,GAAKrB,EAAiBqB,CAAI,GAAKvB,EAAgBuB,CAAI,EAClD,OAAAA,EAAI,IAAKtB,CAAI,EACNsB,EAKR,IAFAE,EAAMxC,EAAWC,GAAQe,CAAI,CAAE,EAAE,UAAW,CAAE,EAC9CuB,EAAMvC,EAAWoC,CAAM,EAAE,UAAW,CAAE,EAChCJ,EAAI,EAAGA,EAAIG,EAAKH,IACrBO,EAAKD,EAAKN,EAAGQ,EAAKxB,EAAKgB,CAAE,CAAE,EAE5B,OAAOM,CACR,CACA,MAAM,IAAI,UAAWpC,EAAQ,wGAAyG,UAAW,CAAE,CAAE,CAAE,CACxJ,CAgBA,SAASuB,GAAS,CACjB,IAAIY,EACAC,EACAG,EACAT,EAUJ,GARAK,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAMd,EAAO,EACFa,IAAU,EACrBC,EAAMd,EAAQ,UAAW,CAAE,CAAE,EAE7Bc,EAAMd,EAAQ,UAAW,CAAE,EAAG,UAAW,CAAE,CAAE,EAEzCc,IAAQ,KASZ,IAPKrB,EAAiBqB,CAAI,EACzBG,EAAM1C,EAAgBuC,EAAK,CAAE,EAClBvB,EAAgBuB,CAAI,EAC/BG,EAAM3C,EAAewC,EAAK,CAAE,EAE5BG,EAAMH,EAEDN,EAAI,EAAGA,EAAIS,EAAI,OAAQT,IAC5BS,EAAKT,CAAE,EAAI,EAGb,OAAOM,CACR,CAcA,SAASZ,EAAMK,EAAM,CACpB,IAAID,EACAY,EACAV,EACJ,GAAKzC,GAAkBwC,CAAI,GAAKA,EAAI,OACnCA,EAAMA,EAAI,eACC,CAACvC,GAAeuC,CAAI,EAC/B,MAAM,IAAI,UAAW7B,EAAQ,4EAA6E6B,CAAI,CAAE,EAEjH,GAAKA,EAAI,WAAa,EAAI,CAQzB,IAPAD,EAAIzB,GAAOE,EAAMwB,EAAI,UAAW,CAAE,EAGlCD,EAAItB,GAAKa,EAAK,OAAO,EAAGS,CAAE,EAG1BY,EAAIrB,EAAMS,CAAE,EACNE,EAAI,EAAGA,EAAIU,EAAE,OAAQV,IAC1B,GAAKU,EAAGV,CAAE,IAAMD,EACf,MAAO,GAITW,EAAE,KAAMX,CAAI,CACb,CACA,MAAO,EACR,CAOA,SAASJ,GAAQ,CAChB,IAAIK,EACJ,IAAMA,EAAI,EAAGA,EAAIX,EAAK,OAAQW,IAC7BX,EAAMW,CAAE,EAAE,OAAS,EAEpBZ,EAAS,CACV,CACD,CAKAjC,EAAO,QAAU+B,KCjXjB,IAAAyB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAU,IAmCVC,GAAiBD,GAAQ,EAK7BD,EAAO,QAAUE,KCnBjB,IAAIC,GAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,GAAU,IAKdF,GAAaC,EAAM,UAAWC,EAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isNonNegativeInteger", "format", "validate", "opts", "options", "require_pool", "__commonJSMin", "exports", "module", "pool", "out", "i", "require_bytes_per_element", "__commonJSMin", "exports", "module", "require_factory", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isCollection", "isTypedArrayLike", "isArrayBuffer", "isComplex64Array", "isComplex128Array", "setReadOnly", "setReadOnlyAccessor", "ctors", "reinterpret64", "reinterpret128", "accessors", "adtype", "format", "ArrayBuffer", "ceil", "floor", "ceil2", "log2", "min", "defaults", "validate", "createPool", "BYTES_PER_ELEMENT", "Complex64Array", "Complex128Array", "isCmplx64Array", "arr", "isCmplx128Array", "factory", "options", "nbytes", "pool", "opts", "err", "malloc", "calloc", "free", "clear", "getBytes", "arraybuffer", "n", "buf", "i", "typedarray", "ctor", "len", "dtype", "nargs", "out", "set", "get", "tmp", "p", "require_main", "__commonJSMin", "exports", "module", "factory", "typedarraypool", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5244595..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,347 +0,0 @@ - -{{alias}}( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - Memory is **uninitialized**, which means that the contents of a returned - typed array may contain sensitive contents. - - The function supports the following data types: - - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - The default typed array data type is `float64`. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}() - [] - > arr = {{alias}}( 'float32' ) - [] - - -{{alias}}( length[, dtype] ) - Returns an uninitialized typed array having a specified length from a typed - array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > arr = {{alias}}( 5, 'int32' ) - - - -{{alias}}( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - This method shares the same security vulnerabilities mentioned above. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc() - - > arr = {{alias}}.malloc( 'float32' ) - - - -{{alias}}.malloc( length[, dtype] ) - Returns a typed array having a specified length from a typed array memory - pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc( 5 ) - - > arr = {{alias}}.malloc( 5, 'int32' ) - - - -{{alias}}.malloc( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}.malloc( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.calloc( [dtype] ) - Returns a zero-initialized typed array from a typed array memory pool. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc() - [] - > arr = {{alias}}.calloc( 'float32' ) - [] - - -{{alias}}.calloc( length[, dtype] ) - Returns a zero-initialized typed array having a specified length from a - typed array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}.calloc( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}.free( buf ) - Frees a typed array or typed array buffer for use in a future allocation. - - Parameters - ---------- - buf: TypedArray|ArrayBuffer - Typed array or typed array buffer to free. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ) - - -{{alias}}.clear() - Clears the typed array pool allowing garbage collection of previously - allocated (and currently free) array buffers. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - > {{alias}}.clear() - - -{{alias}}.highWaterMark - Read-only property returning the pool's high water mark. - - Once a high water mark is reached, typed array allocation fails. - - Examples - -------- - > {{alias}}.highWaterMark - - -{{alias}}.nbytes - Read-only property returning the total number of allocated bytes. - - The returned value is the total accumulated value. Hence, anytime a pool - must allocate a new array buffer (i.e., more memory), the pool increments - this value. - - The only time this value is decremented is when a pool is cleared. - - This behavior means that, while allocated buffers which are never freed may, - in fact, be garbage collected, they continue to count against the high water - mark limit. - - Accordingly, you should *always* free allocated buffers in order to prevent - the pool from believing that non-freed buffers are continually in use. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.nbytes - - -{{alias}}.factory( [options] ) - Creates a typed array pool. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.highWaterMark: integer (optional) - Maximum total memory (in bytes) which can be allocated. - - Returns - ------- - fcn: Function - Function for creating typed arrays from a typed array memory pool. - - Examples - -------- - > var pool = {{alias}}.factory(); - > var arr1 = pool( 3, 'float64' ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 4336c42..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,193 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-empty */ -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import typedarraypool = require( './index' ); - - -// TESTS // - -// The function returns a typed array or null... -{ - typedarraypool(); // $ExpectType TypedArrayOrNull - typedarraypool( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the function is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool( true ); // $ExpectError - typedarraypool( false ); // $ExpectError - typedarraypool( null ); // $ExpectError - typedarraypool( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized data type... -{ - typedarraypool( 4, true ); // $ExpectError - typedarraypool( 4, false ); // $ExpectError - typedarraypool( 4, null ); // $ExpectError - typedarraypool( 4, 'abc' ); // $ExpectError - typedarraypool( 4, 123 ); // $ExpectError - typedarraypool( 4, [] ); // $ExpectError - typedarraypool( 4, {} ); // $ExpectError - typedarraypool( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an incorrect number of arguments... -{ - typedarraypool( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `malloc` method which returns a typed array or null... -{ - typedarraypool.malloc(); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.malloc( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `malloc` method is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool.malloc( true ); // $ExpectError - typedarraypool.malloc( false ); // $ExpectError - typedarraypool.malloc( null ); // $ExpectError - typedarraypool.malloc( {} ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.malloc( 4, true ); // $ExpectError - typedarraypool.malloc( 4, false ); // $ExpectError - typedarraypool.malloc( 4, null ); // $ExpectError - typedarraypool.malloc( 4, 'abc' ); // $ExpectError - typedarraypool.malloc( 4, 123 ); // $ExpectError - typedarraypool.malloc( 4, [] ); // $ExpectError - typedarraypool.malloc( 4, {} ); // $ExpectError - typedarraypool.malloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided an incorrect number of arguments... -{ - typedarraypool.malloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `calloc` method which returns a typed array or null... -{ - typedarraypool.calloc(); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `calloc` method is provided a first argument which is not a number... -{ - typedarraypool.calloc( 'abc' ); // $ExpectError - typedarraypool.calloc( true ); // $ExpectError - typedarraypool.calloc( false ); // $ExpectError - typedarraypool.calloc( null ); // $ExpectError - typedarraypool.calloc( {} ); // $ExpectError - typedarraypool.calloc( [] ); // $ExpectError - typedarraypool.calloc( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.calloc( 4, true ); // $ExpectError - typedarraypool.calloc( 4, false ); // $ExpectError - typedarraypool.calloc( 4, null ); // $ExpectError - typedarraypool.calloc( 4, 'abc' ); // $ExpectError - typedarraypool.calloc( 4, 123 ); // $ExpectError - typedarraypool.calloc( 4, [] ); // $ExpectError - typedarraypool.calloc( 4, {} ); // $ExpectError - typedarraypool.calloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided an incorrect number of arguments... -{ - typedarraypool.calloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `factory` method which returns a typed array pool.. -{ - typedarraypool.factory(); // $ExpectType Pool - typedarraypool.factory( { 'highWaterMark': 556 } ); // $ExpectType Pool -} - -// The compiler throws an error if the `factory` method is provided a `highWaterMark` option which is not a number... -{ - typedarraypool.factory( { 'highWaterMark': true } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': false } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': 'abc' } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': null } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': [] } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': {} } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an incorrect number of arguments... -{ - typedarraypool.factory( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` method which returns void... -{ - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.free( arr ); // $ExpectType void -} - -// The compiler throws an error if the `free` method is provided a first argument which is neither a typed array nor array buffer... -{ - typedarraypool.free( true ); // $ExpectError - typedarraypool.free( false ); // $ExpectError - typedarraypool.free( 123 ); // $ExpectError - typedarraypool.free( 'abc' ); // $ExpectError - typedarraypool.free( null ); // $ExpectError - typedarraypool.free( {} ); // $ExpectError - typedarraypool.free( ( x: number ): number => x ); // $ExpectError -} - -// Attached to the main export is a `clear` method which returns void... -{ - typedarraypool.clear(); // $ExpectType void -} - -// The compiler throws an error if the `clear` method is provided arguments... -{ - typedarraypool.clear( {} ); // $ExpectError - typedarraypool.clear( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `highWaterMark` property... -{ - typedarraypool.highWaterMark; // $ExpectType number -} - -// Attached to the main export is a `nbytes` property... -{ - typedarraypool.nbytes; // $ExpectType number -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 24a7846..0000000 --- a/examples/index.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 randu = require( '@stdlib/random-base-randu' ); -var typedarraypool = require( './../lib' ); - -// Create a typed array pool which can allocate at most 1GB: -var typedarray = typedarraypool.factory({ - 'highWaterMark': 1e9 -}); - -// Inspect the pool: -console.log( 'Max bytes: %d', typedarray.highWaterMark ); -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Allocate an array for storing double-precision floating-point numbers: -var arr1 = typedarray( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Fill the array... -var i; -for ( i = 0; i < arr1.length; i++ ) { - arr1[ i ] = randu(); -} - -// Inspect array contents: -console.log( arr1 ); - -// Free the array: -typedarray.free( arr1 ); - -// Allocate another array similar to the previous one: -var arr2 = typedarray( 5, 'float64' ); -// returns - -// Check that we have been returned a new typed array view: -console.log( arr2 === arr1 ); -// => false - -// Inspect array contents: -console.log( arr2 ); - -// Free the array: -typedarray.free( arr2 ); - -// Allocate an initialized array: -var arr3 = typedarray.calloc( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect array contents: -console.log( arr3 ); - -// Free the array: -typedarray.free( arr3 ); - -// Clear the pool: -typedarray.clear(); - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 4254ef5..0f5442f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike, RealOrComplexTypedArray, NumericDataType as DataType } from '@stdlib/types/array'; import ArrayBuffer = require( '@stdlib/array-buffer' ); diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6e11ad0 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessors@v0.1.0-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.1.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.1.0-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.1.1-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.1.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";function k(e,t){return y(t)?w(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(f("invalid option. `%s` option must be a nonnegative integer. Option: `%s`.","highWaterMark",e.highWaterMark)):null:new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",t))}function M(e){var t,r;for(t=[],r=0;rT.highWaterMark?null:(t=new j(e),w+=e,t)}function B(e,t,r){var s;return 0===t?new e(0):null===(s=A(g(t)*W[r]))?s:new e(s,0,t)}function F(){var e,n,i,m,j,v,u,g,b;if(n=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(i=l(n)))throw new TypeError(f("invalid argument. Must provide a recognized data type. Value: `%s`.",n));if(e<=0)return new i(0);if(r(arguments[0]))return B(i,arguments[0],n);if(s(arguments[0])){if(g=(m=arguments[0]).length,o(m)?m=h(m,0):a(m)?m=d(m,0):/^complex/.test(n)&&(g/=2),null===(j=B(i,g,n)))return j;if(L(j)||V(j))return j.set(m),j;for(u=p(c(m)).accessors[0],v=p(n).accessors[1],b=0;b0){for(t=u(b(e.byteLength)),t=x(E.length-1,t),r=E[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = accessors( adtype( arr ) ).accessors[ 0 ];\n\t\t\tset = accessors( dtype ).accessors[ 1 ];\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","accessors","adtype","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;gwEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,2EAA4E,gBAAiBP,EAAKI,gBAG3H,KARC,IAAIE,UAAWC,EAAQ,qEAAsEN,GAStG,CC/BA,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,iHCaIG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EC/EO,CACNI,cAAiB,kBD+EbkB,UAAUC,SACdF,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOgB,EAAYC,EAAMC,EAAM1B,EAAKI,iBACpCgB,EAAS,EAETO,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB5B,EAAKI,eAC3C4B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOb,CACP,CASD,SAASc,EAAazB,GACrB,IAAI0B,EACAxB,EAMJ,OAHAA,EAAIe,EAAMjB,IAGDD,EAAKe,QAAUf,EAAMG,GAAIY,OAC1Bf,EAAMG,GAAIyB,MAGbhB,EAAOX,EAAIT,EAAKI,cACb,MAER+B,EAAM,IAAIE,EAAa5B,GAGvBW,GAAUX,EAEH0B,EACP,CAWD,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,EACzB,CAkBD,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAtB,EACAP,EACAmC,EACAC,EACAN,EACA7B,EAUJ,GALC8B,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAOzB,EAAO2B,IAEb,MAAM,IAAInC,UAAWC,EAAQ,sEAAuEkC,IAErG,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKlC,EAAsBiB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAvB,EAAMK,UAAW,IACPC,OACL0B,EAAmBhC,GACvBA,EAAMiC,EAAgBjC,EAAK,GAChBkC,EAAkBlC,GAC7BA,EAAMmC,EAAenC,EAAK,GACf,WAAWoC,KAAMZ,KAE5BD,GAAO,GAGK,QADb9B,EAAM4B,EAAYC,EAAMC,EAAKC,IAE5B,OAAO/B,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAImC,IAAK5B,GACFP,EAKR,IAFAoC,EAAMQ,EAAWC,EAAQtC,IAAQqC,UAAW,GAC5CT,EAAMS,EAAWb,GAAQa,UAAW,GAC9B3C,EAAI,EAAGA,EAAI6B,EAAK7B,IACrBkC,EAAKnC,EAAKC,EAAGmC,EAAK7B,EAAKN,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,wGAAyGe,UAAW,IACjJ,CAgBD,SAASO,IACR,IAAIe,EACAlC,EACA8C,EACA7C,EAUJ,GAAa,QANZD,EADc,KADfkC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCkC,EADItC,EAAiBR,GACfwC,EAAgBxC,EAAK,GAChBM,EAAgBN,GACrB0C,EAAe1C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAI6C,EAAIjC,OAAQZ,IAC5B6C,EAAK7C,GAAM,EAGb,OAAOD,CACP,CAcD,SAASoB,EAAMK,GACd,IAAI1B,EACAgD,EACA9C,EACJ,GAAK+C,EAAkBvB,IAASA,EAAIwB,OACnCxB,EAAMA,EAAIwB,YACJ,IAAMC,EAAezB,GAC3B,MAAM,IAAI7B,UAAWC,EAAQ,4EAA6E4B,IAE3G,GAAKA,EAAI0B,WAAa,EAAI,CAQzB,IAPApD,EAAIqD,EAAOpC,EAAMS,EAAI0B,aAGrBpD,EAAIsD,EAAKvD,EAAKe,OAAO,EAAGd,GAGxBgD,EAAIjD,EAAMC,GACJE,EAAI,EAAGA,EAAI8C,EAAElC,OAAQZ,IAC1B,GAAK8C,EAAG9C,KAAQwB,EACf,OAAO,EAITsB,EAAE7C,KAAMuB,EACR,CACD,OAAO,CACP,CAOD,SAASJ,IACR,IAAIpB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKe,OAAQZ,IAC7BH,EAAMG,GAAIY,OAAS,EAEpBH,EAAS,CACT,CACF,CEnTG,IAAC4C,EAAiB7C,ICPrBQ,EAAAsC,EAAA,UAAA9C"} \ No newline at end of file diff --git a/lib/bytes_per_element.json b/lib/bytes_per_element.json deleted file mode 100644 index f97fe70..0000000 --- a/lib/bytes_per_element.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "float64": 8, - "float32": 4, - "int16": 2, - "int32": 4, - "int8": 1, - "uint16": 2, - "uint32": 4, - "uint8": 1, - "uint8c": 1, - "complex64": 8, - "complex128": 16 -} diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index a421711..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +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'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'highWaterMark': 9007199254740992 - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index edfecbe..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,370 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var isComplex64Array = require( '@stdlib/assert-is-complex64array' ); -var isComplex128Array = require( '@stdlib/assert-is-complex128array' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var ctors = require( '@stdlib/array-typed-ctors' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var accessors = require( '@stdlib/array-base-accessors' ); -var adtype = require( '@stdlib/array-dtype' ); -var format = require( '@stdlib/string-format' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil = require( '@stdlib/math-base-special-ceil' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); -var log2 = require( '@stdlib/math-base-special-log2' ); -var min = require( '@stdlib/math-base-special-min' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var createPool = require( './pool.js' ); -var BYTES_PER_ELEMENT = require( './bytes_per_element.json' ); - - -// VARIABLES // - -var Complex64Array = ctors( 'complex64' ); -var Complex128Array = ctors( 'complex128' ); - - -// FUNCTIONS // - -/** -* Tests whether an array is a single-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a single-precision complex floating-point number array -*/ -function isCmplx64Array( arr ) { - return ( arr instanceof Complex64Array ); -} - -/** -* Tests whether an array is a double-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a double-precision complex floating-point number array -*/ -function isCmplx128Array( arr ) { - return ( arr instanceof Complex128Array ); -} - - -// MAIN // - -/** -* Creates a typed array pool. -* -* @param {Options} [options] - pool options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} allocator -* -* @example -* var typedarraypool = factory(); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -function factory( options ) { - var nbytes; - var pool; - var opts; - var err; - - opts = defaults(); - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - pool = createPool( ceil( log2( opts.highWaterMark ) ) ); - nbytes = 0; - - setReadOnly( malloc, 'malloc', malloc ); // circular reference - setReadOnly( malloc, 'calloc', calloc ); - setReadOnly( malloc, 'free', free ); - setReadOnly( malloc, 'clear', clear ); - setReadOnly( malloc, 'highWaterMark', opts.highWaterMark ); - setReadOnlyAccessor( malloc, 'nbytes', getBytes ); - - return malloc; - - /** - * Returns the number of allocated bytes. - * - * @private - * @returns {NonNegativeInteger} number of allocated bytes - */ - function getBytes() { - return nbytes; - } - - /** - * Returns an array buffer. - * - * @private - * @param {NonNegativeInteger} n - number of bytes - * @returns {(ArrayBuffer|null)} array buffer or null - */ - function arraybuffer( n ) { - var buf; - var i; - - // Convert the number of bytes to an index in our pool table: - i = log2( n ); - - // If we already have an available array buffer, use it... - if ( i < pool.length && pool[ i ].length ) { - return pool[ i ].pop(); - } - // Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate... - if ( nbytes+n > opts.highWaterMark ) { - return null; - } - buf = new ArrayBuffer( n ); - - // Update the running counter of allocated bytes: - nbytes += n; - - return buf; - } - - /** - * Returns a typed array. - * - * @private - * @param {Function} ctor - typed array constructor - * @param {NonNegativeInteger} len - view length - * @param {string} dtype - data type - * @returns {(TypedArray|null)} typed array or null - */ - function typedarray( ctor, len, dtype ) { - var buf; - if ( len === 0 ) { - return new ctor( 0 ); - } - buf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] ); - if ( buf === null ) { - return buf; - } - return new ctor( buf, 0, len ); - } - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length or an array-like object - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function malloc() { - var nargs; - var dtype; - var ctor; - var arr; - var out; - var set; - var get; - var len; - var i; - - nargs = arguments.length; - if ( nargs && isString( arguments[ nargs-1 ] ) ) { - nargs -= 1; - dtype = arguments[ nargs ]; - } else { - dtype = 'float64'; - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) ); - } - if ( nargs <= 0 ) { - return new ctor( 0 ); - } - // Check if provided a typed array length... - if ( isNonNegativeInteger( arguments[ 0 ] ) ) { - return typedarray( ctor, arguments[ 0 ], dtype ); - } - // Check if provided an array-like object containing data elements... - if ( isCollection( arguments[ 0 ] ) ) { - arr = arguments[ 0 ]; - len = arr.length; - if ( isComplex128Array( arr ) ) { - arr = reinterpret128( arr, 0 ); - } else if ( isComplex64Array( arr ) ) { - arr = reinterpret64( arr, 0 ); - } else if ( /^complex/.test( dtype ) ) { - // Assume we've been provided an array of interleaved real and imaginary components... - len /= 2; - } - out = typedarray( ctor, len, dtype ); - if ( out === null ) { - return out; - } - if ( isCmplx128Array( out ) || isCmplx64Array( out ) ) { - out.set( arr ); - return out; - } - // Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other "unsafe" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things... - get = accessors( adtype( arr ) ).accessors[ 0 ]; - set = accessors( dtype ).accessors[ 1 ]; - for ( i = 0; i < len; i++ ) { - set( out, i, get( arr, i ) ); - } - return out; - } - throw new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) ); - } - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {NonNegativeInteger} [len=0] - array length - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function calloc() { - var nargs; - var out; - var tmp; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - out = malloc(); - } else if ( nargs === 1 ) { - out = malloc( arguments[ 0 ] ); - } else { - out = malloc( arguments[ 0 ], arguments[ 1 ] ); - } - if ( out !== null ) { - // Initialize the memory... - if ( isCmplx128Array( out ) ) { - tmp = reinterpret128( out, 0 ); - } else if ( isCmplx64Array( out ) ) { - tmp = reinterpret64( out, 0 ); - } else { - tmp = out; - } - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = 0.0; - } - } - return out; - } - - /** - * Frees a typed array or typed array buffer. - * - * ## Notes - * - * - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., "freeing" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool. - * - * @private - * @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free - * @throws {TypeError} must provide a typed array or typed array buffer - * @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed - */ - function free( buf ) { - var n; - var p; - var i; - if ( isTypedArrayLike( buf ) && buf.buffer ) { - buf = buf.buffer; - } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) ); - } - if ( buf.byteLength > 0 ) { - n = floor( log2( buf.byteLength ) ); - - // Prohibit "freeing" array buffers which would potentially allow users to circumvent high water mark limits: - n = min( pool.length-1, n ); - - // Ensure that we do not attempt to free the same buffer more than once... - p = pool[ n ]; - for ( i = 0; i < p.length; i++ ) { - if ( p[ i ] === buf ) { - return false; - } - } - // Add the buffer to our pool of free buffers: - p.push( buf ); - } - return true; - } - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @private - */ - function clear() { - var i; - for ( i = 0; i < pool.length; i++ ) { - pool[ i ].length = 0; - } - nbytes = 0; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6c12a4e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Typed array pool. -* -* @module @stdlib/array-pool -* -* @example -* var typedarraypool = require( '@stdlib/array-pool' ); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8f69ee3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,63 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @name typedarraypool -* @type {Function} -* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a valid array length or an array-like object -* @throws {TypeError} must provide a recognized data type -* @returns {(TypedArray|null)} typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -var typedarraypool = factory(); - - -// EXPORTS // - -module.exports = typedarraypool; diff --git a/lib/pool.js b/lib/pool.js deleted file mode 100644 index 5abd287..0000000 --- a/lib/pool.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Initializes a cache for pooled typed array buffers. -* -* @private -* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size -* @returns {ArrayArray} initialized cache -*/ -function pool( n ) { - var out; - var i; - - out = []; - for ( i = 0; i < n+1; i++ ) { - out.push( [] ); - } - return out; -} - - -// EXPORTS // - -module.exports = pool; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index ce54890..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'highWaterMark': 1024 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'highWaterMark' ) ) { - opts.highWaterMark = options.highWaterMark; - if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 9a6418f..bd7b179 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Typed array pool.", "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,76 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessors": "^0.1.0", - "@stdlib/array-buffer": "^0.1.0", - "@stdlib/array-dtype": "^0.1.0", - "@stdlib/array-typed-ctors": "^0.1.0", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-arraybuffer": "^0.1.1", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-complex128array": "^0.1.0", - "@stdlib/assert-is-complex64array": "^0.1.0", - "@stdlib/assert-is-nonnegative-integer": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/assert-is-string": "^0.1.1", - "@stdlib/assert-is-typed-array-like": "^0.1.0", - "@stdlib/math-base-special-ceil": "^0.1.1", - "@stdlib/math-base-special-ceil2": "^0.1.0", - "@stdlib/math-base-special-floor": "^0.1.1", - "@stdlib/math-base-special-log2": "^0.1.1", - "@stdlib/math-base-special-min": "^0.1.1", - "@stdlib/strided-base-reinterpret-complex128": "^0.1.1", - "@stdlib/strided-base-reinterpret-complex64": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.1.0", - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-float32": "^0.1.1", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/array-int16": "^0.1.1", - "@stdlib/array-int32": "^0.1.1", - "@stdlib/array-int8": "^0.1.1", - "@stdlib/array-uint16": "^0.1.1", - "@stdlib/array-uint32": "^0.1.1", - "@stdlib/array-uint8": "^0.1.1", - "@stdlib/array-uint8c": "^0.1.1", - "@stdlib/assert-instance-of": "^0.1.1", - "@stdlib/assert-is-complex-typed-array": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-typed-array": "^0.1.0", - "@stdlib/complex-float32": "^0.1.1", - "@stdlib/complex-float64": "^0.1.1", - "@stdlib/complex-imag": "^0.1.1", - "@stdlib/complex-imagf": "^0.1.1", - "@stdlib/complex-real": "^0.1.1", - "@stdlib/complex-realf": "^0.1.1", - "@stdlib/math-base-special-pow": "^0.1.0", - "@stdlib/random-base-randu": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..39dc408 --- /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.factory.js b/test/test.factory.js deleted file mode 100644 index 396aee2..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,2240 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function (no options)', function test( t ) { - t.strictEqual( typeof factory(), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - t.strictEqual( typeof factory( {} ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided a `highWaterMark` option which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (length)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a function which returns a typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, length)', function test( t ) { - var typedarraypool = factory(); - var arr; - - arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a `malloc` method which is a circular reference', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - var buf; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the returned function is a property which returns the pool\'s high water mark', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function supports specifying a high water mark which limits the total amount of memory a pool can allocate', function test( t ) { - var typedarraypool; - var arr1; - var arr2; - - typedarraypool = factory({ - 'highWaterMark': 64 // bytes - }); - - typedarraypool.clear(); - - arr1 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr1.length, 8, 'returns expected value' ); - t.strictEqual( arr1.byteLength, 64, 'returns expected value' ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - typedarraypool.free( arr1 ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Create an array which is less than or equal to the high water mark: - arr2 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr2.length, 8, 'returns expected value' ); - t.strictEqual( arr2.byteLength, 64, 'returns expected value' ); - - typedarraypool.free( arr2 ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a property which returns the total number of accumulated bytes', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var typedarraypool; - var arrs; - var i; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 54aa5ee..0000000 --- a/test/test.js +++ /dev/null @@ -1,1797 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var typedarraypool = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -}); From bfd02873ccaab04d5c3129c06c1b1530343cd41b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 16 Jan 2024 08:39:29 +0000 Subject: [PATCH 061/103] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a87af10..bf25163 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "@stdlib/math-base-special-min": "^0.1.1", "@stdlib/strided-base-reinterpret-complex128": "^0.1.1", "@stdlib/strided-base-reinterpret-complex64": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From 1022368bfe32a4561cc9f078cd1c670cf08643f3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 16 Jan 2024 08:40:05 +0000 Subject: [PATCH 062/103] Remove files --- index.d.ts | 359 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6541 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 0f5442f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,359 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike, RealOrComplexTypedArray, NumericDataType as DataType } from '@stdlib/types/array'; -import ArrayBuffer = require( '@stdlib/array-buffer' ); - -/** -* Typed array or null. -*/ -type TypedArrayOrNull = RealOrComplexTypedArray | null; - -/** -* Interface defining pool options. -*/ -interface Options { - /** - * Maximum total memory which can be allocated. - */ - highWaterMark?: number; -} - -/** -* Pool interface. -*/ -interface Pool { - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr = typedarraypool(); - * // returns [] - * - * @example - * var arr = typedarraypool( 'float32' ); - * // returns [] - */ - ( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * // Allocate an array of doubles: - * var arr = typedarraypool( 5, 'float64' ); - * // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * typedarraypool.free( arr ); - * - * @example - * var arr1 = typedarraypool( [ 0.5, 0.5, 0.5 ] ); - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * @example - * var arr1 = [ 0.5, 0.5, 0.5 ]; - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - */ - ( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc(); - * // returns [] - * - * var arr2 = typedarraypool.calloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param length - typed array length - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc( 5 ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * var arr2 = typedarraypool.calloc( 5, 'uint8' ); - * // returns [ 0, 0, 0, 0, 0 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( length: number, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc(); - * // returns [] - * - * var arr2 = typedarraypool.malloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc( 5 ); - * // returns - * - * var arr2 = typedarraypool.malloc( 5, 'uint8' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 5.0, -3.0, 2.0 ] ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr2 = typedarraypool.malloc( arr1 ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr3 = typedarraypool.malloc( arr1, 'int32' ); - * // returns [ 5, -3, 2 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * typedarraypool.free( arr3 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ] ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * var arr2 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ], 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Frees a typed array or typed array buffer for use in a future allocation. - * - * @param buf - typed array or typed array buffer to free - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array for use in a future allocation: - * typedarraypool.free( arr ); - * - * // Create another typed array: - * arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array buffer for use in a future allocation: - * typedarraypool.free( arr.buffer ); - */ - free( buf: RealOrComplexTypedArray | ArrayBuffer ): void; - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr ); - * - * // ... - * - * // Clear all freed buffers: - * typedarraypool.clear(); - */ - clear(): void; - - /** - * Read-only property returning the pool's high water mark. - * - * ## Notes - * - * - Once a high water mark is reached, typed array allocation fails. - * - * @example - * var limit = typedarraypool.highWaterMark; - * // returns - */ - readonly highWaterMark: number; - - /** - * Read-only property returning the total number of allocated bytes. - * - * @example - * var arr = typedarraypool( 5, 'float64' ); - * - * var nbytes = typedarraypool.nbytes; - * // returns - */ - readonly nbytes: number; - - /** - * Creates a typed array pool. - * - * @param options - pool options - * @param options.highWaterMark - maximum total memory which can be allocated - * @throws must provide valid options - * @returns allocator - * - * @example - * var allocator = typedarraypool.factory(); - * - * // Allocate an array of doubles: - * var arr = allocator( 5, 'float64' ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * allocator.free( arr ); - */ - factory( options?: Options ): Pool; -} - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @param arg - an array length or an array-like object -* @param dtype - data type (default: 'float64') -* @returns typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -declare var typedarraypool: Pool; - - -// EXPORTS // - -export = typedarraypool; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 6e11ad0..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessors@v0.1.0-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.1.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.1.0-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.1.1-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.1.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";function k(e,t){return y(t)?w(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(f("invalid option. `%s` option must be a nonnegative integer. Option: `%s`.","highWaterMark",e.highWaterMark)):null:new TypeError(f("invalid argument. Options argument must be an object. Value: `%s`.",t))}function M(e){var t,r;for(t=[],r=0;rT.highWaterMark?null:(t=new j(e),w+=e,t)}function B(e,t,r){var s;return 0===t?new e(0):null===(s=A(g(t)*W[r]))?s:new e(s,0,t)}function F(){var e,n,i,m,j,v,u,g,b;if(n=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:"float64",null===(i=l(n)))throw new TypeError(f("invalid argument. Must provide a recognized data type. Value: `%s`.",n));if(e<=0)return new i(0);if(r(arguments[0]))return B(i,arguments[0],n);if(s(arguments[0])){if(g=(m=arguments[0]).length,o(m)?m=h(m,0):a(m)?m=d(m,0):/^complex/.test(n)&&(g/=2),null===(j=B(i,g,n)))return j;if(L(j)||V(j))return j.set(m),j;for(u=p(c(m)).accessors[0],v=p(n).accessors[1],b=0;b0){for(t=u(b(e.byteLength)),t=x(E.length-1,t),r=E[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = 'float64';\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = accessors( adtype( arr ) ).accessors[ 0 ];\n\t\t\tset = accessors( dtype ).accessors[ 1 ];\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","get","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","accessors","adtype","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;gwEAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,2EAA4E,gBAAiBP,EAAKI,gBAG3H,KARC,IAAIE,UAAWC,EAAQ,qEAAsEN,GAStG,CC/BA,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,iHCaIG,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASlB,GACjB,IAAImB,EACAZ,EACAR,EACAqB,EAGJ,GADArB,EC/EO,CACNI,cAAiB,kBD+EbkB,UAAUC,SACdF,EAAMtB,EAAUC,EAAMC,IAErB,MAAMoB,EAaR,OAVAb,EAAOgB,EAAYC,EAAMC,EAAM1B,EAAKI,iBACpCgB,EAAS,EAETO,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB5B,EAAKI,eAC3C4B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOb,CACP,CASD,SAASc,EAAazB,GACrB,IAAI0B,EACAxB,EAMJ,OAHAA,EAAIe,EAAMjB,IAGDD,EAAKe,QAAUf,EAAMG,GAAIY,OAC1Bf,EAAMG,GAAIyB,MAGbhB,EAAOX,EAAIT,EAAKI,cACb,MAER+B,EAAM,IAAIE,EAAa5B,GAGvBW,GAAUX,EAEH0B,EACP,CAWD,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,EACzB,CAkBD,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAtB,EACAP,EACAmC,EACAC,EACAN,EACA7B,EAUJ,GALC8B,GAHDG,EAAQtB,UAAUC,SACJwB,EAAUzB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGD,UAGK,QADdL,EAAOzB,EAAO2B,IAEb,MAAM,IAAInC,UAAWC,EAAQ,sEAAuEkC,IAErG,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKlC,EAAsBiB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKO,EAAc1B,UAAW,IAAQ,CAYrC,GAVAkB,GADAvB,EAAMK,UAAW,IACPC,OACL0B,EAAmBhC,GACvBA,EAAMiC,EAAgBjC,EAAK,GAChBkC,EAAkBlC,GAC7BA,EAAMmC,EAAenC,EAAK,GACf,WAAWoC,KAAMZ,KAE5BD,GAAO,GAGK,QADb9B,EAAM4B,EAAYC,EAAMC,EAAKC,IAE5B,OAAO/B,EAER,GAAKQ,EAAiBR,IAASM,EAAgBN,GAE9C,OADAA,EAAImC,IAAK5B,GACFP,EAKR,IAFAoC,EAAMQ,EAAWC,EAAQtC,IAAQqC,UAAW,GAC5CT,EAAMS,EAAWb,GAAQa,UAAW,GAC9B3C,EAAI,EAAGA,EAAI6B,EAAK7B,IACrBkC,EAAKnC,EAAKC,EAAGmC,EAAK7B,EAAKN,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,wGAAyGe,UAAW,IACjJ,CAgBD,SAASO,IACR,IAAIe,EACAlC,EACA8C,EACA7C,EAUJ,GAAa,QANZD,EADc,KADfkC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCkC,EADItC,EAAiBR,GACfwC,EAAgBxC,EAAK,GAChBM,EAAgBN,GACrB0C,EAAe1C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAI6C,EAAIjC,OAAQZ,IAC5B6C,EAAK7C,GAAM,EAGb,OAAOD,CACP,CAcD,SAASoB,EAAMK,GACd,IAAI1B,EACAgD,EACA9C,EACJ,GAAK+C,EAAkBvB,IAASA,EAAIwB,OACnCxB,EAAMA,EAAIwB,YACJ,IAAMC,EAAezB,GAC3B,MAAM,IAAI7B,UAAWC,EAAQ,4EAA6E4B,IAE3G,GAAKA,EAAI0B,WAAa,EAAI,CAQzB,IAPApD,EAAIqD,EAAOpC,EAAMS,EAAI0B,aAGrBpD,EAAIsD,EAAKvD,EAAKe,OAAO,EAAGd,GAGxBgD,EAAIjD,EAAMC,GACJE,EAAI,EAAGA,EAAI8C,EAAElC,OAAQZ,IAC1B,GAAK8C,EAAG9C,KAAQwB,EACf,OAAO,EAITsB,EAAE7C,KAAMuB,EACR,CACD,OAAO,CACP,CAOD,SAASJ,IACR,IAAIpB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKe,OAAQZ,IAC7BH,EAAMG,GAAIY,OAAS,EAEpBH,EAAS,CACT,CACF,CEnTG,IAAC4C,EAAiB7C,ICPrBQ,EAAAsC,EAAA,UAAA9C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 39dc408..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From dad1a97d174757d9b109bd6a444a5460df20e237 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 16 Jan 2024 08:41:10 +0000 Subject: [PATCH 063/103] 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 | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 43 +- SECURITY.md | 5 - benchmark/benchmark.calloc.js | 246 - benchmark/benchmark.factory.js | 71 - benchmark/benchmark.js | 246 - benchmark/benchmark.length.complex128.js | 102 - benchmark/benchmark.length.complex64.js | 102 - benchmark/benchmark.length.float32.js | 102 - benchmark/benchmark.length.float64.js | 102 - benchmark/benchmark.length.int16.js | 102 - benchmark/benchmark.length.int32.js | 102 - benchmark/benchmark.length.int8.js | 102 - benchmark/benchmark.length.uint16.js | 102 - benchmark/benchmark.length.uint32.js | 102 - benchmark/benchmark.length.uint8.js | 102 - benchmark/benchmark.length.uint8c.js | 102 - benchmark/benchmark.malloc.js | 246 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 347 -- docs/types/test.ts | 193 - examples/index.js | 80 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/bytes_per_element.json | 13 - lib/defaults.js | 42 - lib/factory.js | 372 -- lib/index.js | 56 - lib/main.js | 63 - lib/pool.js | 44 - lib/validate.js | 66 - package.json | 98 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 2240 -------- test/test.js | 1797 ------ 62 files changed, 6206 insertions(+), 10641 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.calloc.js delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.complex128.js delete mode 100644 benchmark/benchmark.length.complex64.js delete mode 100644 benchmark/benchmark.length.float32.js delete mode 100644 benchmark/benchmark.length.float64.js delete mode 100644 benchmark/benchmark.length.int16.js delete mode 100644 benchmark/benchmark.length.int32.js delete mode 100644 benchmark/benchmark.length.int8.js delete mode 100644 benchmark/benchmark.length.uint16.js delete mode 100644 benchmark/benchmark.length.uint32.js delete mode 100644 benchmark/benchmark.length.uint8.js delete mode 100644 benchmark/benchmark.length.uint8c.js delete mode 100644 benchmark/benchmark.malloc.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/bytes_per_element.json delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/pool.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ea35f20..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/array/pool) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6f7c875..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/array/pool) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 37cfff8..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -493,7 +492,7 @@ console.log( 'nbytes: %d', typedarray.nbytes ); ## 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]. @@ -559,7 +558,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/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.calloc.js b/benchmark/benchmark.calloc.js deleted file mode 100644 index fd8f53d..0000000 --- a/benchmark/benchmark.calloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':calloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 58918bb..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = typedarray.factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:highWaterMark', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'highWaterMark': 0 - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.highWaterMark = i; - f = typedarray.factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 4310559..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.complex128.js b/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 12c6668..0000000 --- a/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex64.js b/benchmark/benchmark.length.complex64.js deleted file mode 100644 index ca2b45c..0000000 --- a/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float32.js b/benchmark/benchmark.length.float32.js deleted file mode 100644 index b3b4508..0000000 --- a/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float64.js b/benchmark/benchmark.length.float64.js deleted file mode 100644 index 5f0132d..0000000 --- a/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int16.js b/benchmark/benchmark.length.int16.js deleted file mode 100644 index 9f253cb..0000000 --- a/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int32.js b/benchmark/benchmark.length.int32.js deleted file mode 100644 index f83e795..0000000 --- a/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int8.js b/benchmark/benchmark.length.int8.js deleted file mode 100644 index 5b01174..0000000 --- a/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint16.js b/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 32b0a5d..0000000 --- a/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint32.js b/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 290b90c..0000000 --- a/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8.js b/benchmark/benchmark.length.uint8.js deleted file mode 100644 index ff7d733..0000000 --- a/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8c.js b/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index 8f0d10a..0000000 --- a/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.malloc.js b/benchmark/benchmark.malloc.js deleted file mode 100644 index 1661907..0000000 --- a/benchmark/benchmark.malloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':malloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 9689761..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/array/pool" -%% click B href "https://github.com/stdlib-js/array-pool/tree/main" -%% click C href "https://github.com/stdlib-js/array-pool/tree/production" -%% click D href "https://github.com/stdlib-js/array-pool/tree/esm" -%% click E href "https://github.com/stdlib-js/array-pool/tree/deno" -%% click F href "https://github.com/stdlib-js/array-pool/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/pool -[production-url]: https://github.com/stdlib-js/array-pool/tree/production -[deno-url]: https://github.com/stdlib-js/array-pool/tree/deno -[umd-url]: https://github.com/stdlib-js/array-pool/tree/umd -[esm-url]: https://github.com/stdlib-js/array-pool/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 5160b6f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import typedarraypool from '../docs/types/index'; -export = typedarraypool; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 71bbc0d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var l=function(n,i){return function(){return i||n((i={exports:{}}).exports,i),i.exports}};var M=l(function(Er,w){ -function U(){return{highWaterMark:9007199254740992}}w.exports=U -});var T=l(function(Tr,E){ -var z=require('@stdlib/assert-is-plain-object/dist'),G=require('@stdlib/assert-has-own-property/dist'),H=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,k=require('@stdlib/error-tools-fmtprodmsg/dist');function J(n,i){return z(i)?G(i,"highWaterMark")&&(n.highWaterMark=i.highWaterMark,!H(n.highWaterMark))?new TypeError(k('01H2t',"highWaterMark",n.highWaterMark)):null:new TypeError(k('01H2V',i));}E.exports=J -});var C=l(function(Wr,W){ -function K(n){var i,u;for(i=[],u=0;uv.highWaterMark?null:(e=new sr(r),i+=r,e)}function d(r,e,t){var a;return e===0?new r(0):(a=F(vr(e)*pr[t]),a===null?a:new r(a,0,e))}function s(){var r,e,t,a,o,x,A,c,f;if(r=arguments.length,r&&X(arguments[r-1])?(r-=1,e=arguments[r]):e=mr,t=y(e),t===null)throw new TypeError(p('01H2Y',e));if(r<=0)return new t(0);if(Z(arguments[0]))return d(t,arguments[0],e);if($(arguments[0])){if(a=arguments[0],c=a.length,tr(a)?a=b(a,0):ar(a)?a=P(a,0):/^complex/.test(e)&&(c/=2),o=d(t,c,e),o===null)return o;if(B(o)||R(o))return o.set(a),o;for(A=L(nr(a)).accessors[0],x=L(e).accessors[1],f=0;f0){for(e=lr(m(r.byteLength)),e=fr(u.length-1,e),t=u[e],a=0;a[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = accessors( adtype( arr ) ).accessors[ 0 ];\n\t\t\tset = accessors( dtype ).accessors[ 1 ];\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nmodule.exports = typedarraypool;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* var typedarraypool = require( '@stdlib/array-pool' );\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,cAAiB,gBAClB,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,eAAgB,IACzCD,EAAK,cAAgBC,EAAQ,cACxB,CAACJ,EAAsBG,EAAK,aAAc,GACvC,IAAI,UAAWF,EAAQ,2EAA4E,gBAAiBE,EAAK,aAAc,CAAE,EAG3I,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cA6BA,SAASC,EAAM,EAAI,CAClB,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAI,EAAE,EAAGA,IACrBD,EAAI,KAAM,CAAC,CAAE,EAEd,OAAOA,CACR,CAKAF,EAAO,QAAUC,IC3CjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,QAAW,EACX,QAAW,EACX,MAAS,EACT,MAAS,EACT,KAAQ,EACR,OAAU,EACV,OAAU,EACV,MAAS,EACT,OAAU,EACT,UAAa,EACb,WAAc,EAChB,ICZA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAe,QAAS,8BAA+B,EACvDC,GAAmB,QAAS,oCAAqC,EACjEC,GAAgB,QAAS,+BAAgC,EACzDC,GAAmB,QAAS,kCAAmC,EAC/DC,GAAoB,QAAS,mCAAoC,EACjEC,EAAc,QAAS,uDAAwD,EAC/EC,GAAsB,QAAS,uDAAwD,EACvFC,EAAQ,QAAS,2BAA4B,EAC7CC,EAAgB,QAAS,4CAA6C,EACtEC,EAAiB,QAAS,6CAA8C,EACxEC,EAAY,QAAS,8BAA+B,EACpDC,GAAS,QAAS,qBAAsB,EACxCC,GAAiB,QAAS,wBAAyB,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,GAAc,QAAS,sBAAuB,EAC9CC,GAAO,QAAS,gCAAiC,EACjDC,GAAQ,QAAS,iCAAkC,EACnDC,GAAQ,QAAS,iCAAkC,EACnDC,EAAO,QAAS,gCAAiC,EACjDC,GAAM,QAAS,+BAAgC,EAC/CC,GAAW,IACXC,GAAW,IACXC,GAAa,IACbC,GAAoB,IAKpBC,GAAgBZ,GAAe,IAAK,gBAAiB,EACrDa,GAAiBlB,EAAO,WAAY,EACpCmB,GAAkBnB,EAAO,YAAa,EAY1C,SAASoB,EAAgBC,EAAM,CAC9B,OAASA,aAAeH,EACzB,CASA,SAASI,EAAiBD,EAAM,CAC/B,OAASA,aAAeF,EACzB,CA6BA,SAASI,GAASC,EAAU,CAC3B,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,EAAOd,GAAS,EACX,UAAU,SACde,EAAMd,GAAUa,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAAF,EAAOX,GAAYP,GAAMG,EAAMgB,EAAK,aAAc,CAAE,CAAE,EACtDF,EAAS,EAET3B,EAAa+B,EAAQ,SAAUA,CAAO,EACtC/B,EAAa+B,EAAQ,SAAUC,CAAO,EACtChC,EAAa+B,EAAQ,OAAQE,CAAK,EAClCjC,EAAa+B,EAAQ,QAASG,CAAM,EACpClC,EAAa+B,EAAQ,gBAAiBF,EAAK,aAAc,EACzD5B,GAAqB8B,EAAQ,SAAUI,CAAS,EAEzCJ,EAQP,SAASI,GAAW,CACnB,OAAOR,CACR,CASA,SAASS,EAAaC,EAAI,CACzB,IAAIC,EACAC,EAMJ,OAHAA,EAAI1B,EAAMwB,CAAE,EAGPE,EAAIX,EAAK,QAAUA,EAAMW,CAAE,EAAE,OAC1BX,EAAMW,CAAE,EAAE,IAAI,EAGjBZ,EAAOU,EAAIR,EAAK,cACb,MAERS,EAAM,IAAI7B,GAAa4B,CAAE,EAGzBV,GAAUU,EAEHC,EACR,CAWA,SAASE,EAAYC,EAAMC,EAAKC,EAAQ,CACvC,IAAIL,EACJ,OAAKI,IAAQ,EACL,IAAID,EAAM,CAAE,GAEpBH,EAAMF,EAAaxB,GAAO8B,CAAI,EAAExB,GAAmByB,CAAM,CAAE,EACtDL,IAAQ,KACLA,EAED,IAAIG,EAAMH,EAAK,EAAGI,CAAI,EAC9B,CAkBA,SAASX,GAAS,CACjB,IAAIa,EACAD,EACAF,EACAlB,EACAsB,EACAC,EACAC,EACAL,EACAH,EAUJ,GARAK,EAAQ,UAAU,OACbA,GAASnD,EAAU,UAAWmD,EAAM,CAAE,CAAE,GAC5CA,GAAS,EACTD,EAAQ,UAAWC,CAAM,GAEzBD,EAAQxB,GAETsB,EAAOvC,EAAOyC,CAAM,EACfF,IAAS,KACb,MAAM,IAAI,UAAWjC,EAAQ,sEAAuEmC,CAAM,CAAE,EAE7G,GAAKC,GAAS,EACb,OAAO,IAAIH,EAAM,CAAE,EAGpB,GAAK/C,EAAsB,UAAW,CAAE,CAAE,EACzC,OAAO8C,EAAYC,EAAM,UAAW,CAAE,EAAGE,CAAM,EAGhD,GAAKhD,EAAc,UAAW,CAAE,CAAE,EAAI,CAYrC,GAXA4B,EAAM,UAAW,CAAE,EACnBmB,EAAMnB,EAAI,OACLxB,GAAmBwB,CAAI,EAC3BA,EAAMnB,EAAgBmB,EAAK,CAAE,EAClBzB,GAAkByB,CAAI,EACjCA,EAAMpB,EAAeoB,EAAK,CAAE,EACjB,WAAW,KAAMoB,CAAM,IAElCD,GAAO,GAERG,EAAML,EAAYC,EAAMC,EAAKC,CAAM,EAC9BE,IAAQ,KACZ,OAAOA,EAER,GAAKrB,EAAiBqB,CAAI,GAAKvB,EAAgBuB,CAAI,EAClD,OAAAA,EAAI,IAAKtB,CAAI,EACNsB,EAKR,IAFAE,EAAM1C,EAAWC,GAAQiB,CAAI,CAAE,EAAE,UAAW,CAAE,EAC9CuB,EAAMzC,EAAWsC,CAAM,EAAE,UAAW,CAAE,EAChCJ,EAAI,EAAGA,EAAIG,EAAKH,IACrBO,EAAKD,EAAKN,EAAGQ,EAAKxB,EAAKgB,CAAE,CAAE,EAE5B,OAAOM,CACR,CACA,MAAM,IAAI,UAAWrC,EAAQ,wGAAyG,UAAW,CAAE,CAAE,CAAE,CACxJ,CAgBA,SAASwB,GAAS,CACjB,IAAIY,EACAC,EACAG,EACAT,EAUJ,GARAK,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAMd,EAAO,EACFa,IAAU,EACrBC,EAAMd,EAAQ,UAAW,CAAE,CAAE,EAE7Bc,EAAMd,EAAQ,UAAW,CAAE,EAAG,UAAW,CAAE,CAAE,EAEzCc,IAAQ,KASZ,IAPKrB,EAAiBqB,CAAI,EACzBG,EAAM5C,EAAgByC,EAAK,CAAE,EAClBvB,EAAgBuB,CAAI,EAC/BG,EAAM7C,EAAe0C,EAAK,CAAE,EAE5BG,EAAMH,EAEDN,EAAI,EAAGA,EAAIS,EAAI,OAAQT,IAC5BS,EAAKT,CAAE,EAAI,EAGb,OAAOM,CACR,CAcA,SAASZ,EAAMK,EAAM,CACpB,IAAID,EACAY,EACAV,EACJ,GAAK3C,GAAkB0C,CAAI,GAAKA,EAAI,OACnCA,EAAMA,EAAI,eACC,CAACzC,GAAeyC,CAAI,EAC/B,MAAM,IAAI,UAAW9B,EAAQ,4EAA6E8B,CAAI,CAAE,EAEjH,GAAKA,EAAI,WAAa,EAAI,CAQzB,IAPAD,EAAI1B,GAAOE,EAAMyB,EAAI,UAAW,CAAE,EAGlCD,EAAIvB,GAAKc,EAAK,OAAO,EAAGS,CAAE,EAG1BY,EAAIrB,EAAMS,CAAE,EACNE,EAAI,EAAGA,EAAIU,EAAE,OAAQV,IAC1B,GAAKU,EAAGV,CAAE,IAAMD,EACf,MAAO,GAITW,EAAE,KAAMX,CAAI,CACb,CACA,MAAO,EACR,CAOA,SAASJ,GAAQ,CAChB,IAAIK,EACJ,IAAMA,EAAI,EAAGA,EAAIX,EAAK,OAAQW,IAC7BX,EAAMW,CAAE,EAAE,OAAS,EAEpBZ,EAAS,CACV,CACD,CAKAnC,EAAO,QAAUiC,KCnXjB,IAAAyB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAU,IAmCVC,GAAiBD,GAAQ,EAK7BD,EAAO,QAAUE,KCnBjB,IAAIC,GAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,GAAU,IAKdF,GAAaC,EAAM,UAAWC,EAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isNonNegativeInteger", "format", "validate", "opts", "options", "require_pool", "__commonJSMin", "exports", "module", "pool", "out", "i", "require_bytes_per_element", "__commonJSMin", "exports", "module", "require_factory", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isCollection", "isTypedArrayLike", "isArrayBuffer", "isComplex64Array", "isComplex128Array", "setReadOnly", "setReadOnlyAccessor", "ctors", "reinterpret64", "reinterpret128", "accessors", "adtype", "ARRAY_DEFAULTS", "format", "ArrayBuffer", "ceil", "floor", "ceil2", "log2", "min", "defaults", "validate", "createPool", "BYTES_PER_ELEMENT", "DEFAULT_DTYPE", "Complex64Array", "Complex128Array", "isCmplx64Array", "arr", "isCmplx128Array", "factory", "options", "nbytes", "pool", "opts", "err", "malloc", "calloc", "free", "clear", "getBytes", "arraybuffer", "n", "buf", "i", "typedarray", "ctor", "len", "dtype", "nargs", "out", "set", "get", "tmp", "p", "require_main", "__commonJSMin", "exports", "module", "factory", "typedarraypool", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5244595..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,347 +0,0 @@ - -{{alias}}( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - Memory is **uninitialized**, which means that the contents of a returned - typed array may contain sensitive contents. - - The function supports the following data types: - - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - The default typed array data type is `float64`. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}() - [] - > arr = {{alias}}( 'float32' ) - [] - - -{{alias}}( length[, dtype] ) - Returns an uninitialized typed array having a specified length from a typed - array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > arr = {{alias}}( 5, 'int32' ) - - - -{{alias}}( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - This method shares the same security vulnerabilities mentioned above. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc() - - > arr = {{alias}}.malloc( 'float32' ) - - - -{{alias}}.malloc( length[, dtype] ) - Returns a typed array having a specified length from a typed array memory - pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc( 5 ) - - > arr = {{alias}}.malloc( 5, 'int32' ) - - - -{{alias}}.malloc( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}.malloc( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.calloc( [dtype] ) - Returns a zero-initialized typed array from a typed array memory pool. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc() - [] - > arr = {{alias}}.calloc( 'float32' ) - [] - - -{{alias}}.calloc( length[, dtype] ) - Returns a zero-initialized typed array having a specified length from a - typed array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}.calloc( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}.free( buf ) - Frees a typed array or typed array buffer for use in a future allocation. - - Parameters - ---------- - buf: TypedArray|ArrayBuffer - Typed array or typed array buffer to free. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ) - - -{{alias}}.clear() - Clears the typed array pool allowing garbage collection of previously - allocated (and currently free) array buffers. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - > {{alias}}.clear() - - -{{alias}}.highWaterMark - Read-only property returning the pool's high water mark. - - Once a high water mark is reached, typed array allocation fails. - - Examples - -------- - > {{alias}}.highWaterMark - - -{{alias}}.nbytes - Read-only property returning the total number of allocated bytes. - - The returned value is the total accumulated value. Hence, anytime a pool - must allocate a new array buffer (i.e., more memory), the pool increments - this value. - - The only time this value is decremented is when a pool is cleared. - - This behavior means that, while allocated buffers which are never freed may, - in fact, be garbage collected, they continue to count against the high water - mark limit. - - Accordingly, you should *always* free allocated buffers in order to prevent - the pool from believing that non-freed buffers are continually in use. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.nbytes - - -{{alias}}.factory( [options] ) - Creates a typed array pool. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.highWaterMark: integer (optional) - Maximum total memory (in bytes) which can be allocated. - - Returns - ------- - fcn: Function - Function for creating typed arrays from a typed array memory pool. - - Examples - -------- - > var pool = {{alias}}.factory(); - > var arr1 = pool( 3, 'float64' ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 4336c42..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,193 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-empty */ -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import typedarraypool = require( './index' ); - - -// TESTS // - -// The function returns a typed array or null... -{ - typedarraypool(); // $ExpectType TypedArrayOrNull - typedarraypool( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the function is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool( true ); // $ExpectError - typedarraypool( false ); // $ExpectError - typedarraypool( null ); // $ExpectError - typedarraypool( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized data type... -{ - typedarraypool( 4, true ); // $ExpectError - typedarraypool( 4, false ); // $ExpectError - typedarraypool( 4, null ); // $ExpectError - typedarraypool( 4, 'abc' ); // $ExpectError - typedarraypool( 4, 123 ); // $ExpectError - typedarraypool( 4, [] ); // $ExpectError - typedarraypool( 4, {} ); // $ExpectError - typedarraypool( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an incorrect number of arguments... -{ - typedarraypool( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `malloc` method which returns a typed array or null... -{ - typedarraypool.malloc(); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.malloc( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `malloc` method is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool.malloc( true ); // $ExpectError - typedarraypool.malloc( false ); // $ExpectError - typedarraypool.malloc( null ); // $ExpectError - typedarraypool.malloc( {} ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.malloc( 4, true ); // $ExpectError - typedarraypool.malloc( 4, false ); // $ExpectError - typedarraypool.malloc( 4, null ); // $ExpectError - typedarraypool.malloc( 4, 'abc' ); // $ExpectError - typedarraypool.malloc( 4, 123 ); // $ExpectError - typedarraypool.malloc( 4, [] ); // $ExpectError - typedarraypool.malloc( 4, {} ); // $ExpectError - typedarraypool.malloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided an incorrect number of arguments... -{ - typedarraypool.malloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `calloc` method which returns a typed array or null... -{ - typedarraypool.calloc(); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `calloc` method is provided a first argument which is not a number... -{ - typedarraypool.calloc( 'abc' ); // $ExpectError - typedarraypool.calloc( true ); // $ExpectError - typedarraypool.calloc( false ); // $ExpectError - typedarraypool.calloc( null ); // $ExpectError - typedarraypool.calloc( {} ); // $ExpectError - typedarraypool.calloc( [] ); // $ExpectError - typedarraypool.calloc( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.calloc( 4, true ); // $ExpectError - typedarraypool.calloc( 4, false ); // $ExpectError - typedarraypool.calloc( 4, null ); // $ExpectError - typedarraypool.calloc( 4, 'abc' ); // $ExpectError - typedarraypool.calloc( 4, 123 ); // $ExpectError - typedarraypool.calloc( 4, [] ); // $ExpectError - typedarraypool.calloc( 4, {} ); // $ExpectError - typedarraypool.calloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided an incorrect number of arguments... -{ - typedarraypool.calloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `factory` method which returns a typed array pool.. -{ - typedarraypool.factory(); // $ExpectType Pool - typedarraypool.factory( { 'highWaterMark': 556 } ); // $ExpectType Pool -} - -// The compiler throws an error if the `factory` method is provided a `highWaterMark` option which is not a number... -{ - typedarraypool.factory( { 'highWaterMark': true } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': false } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': 'abc' } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': null } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': [] } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': {} } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an incorrect number of arguments... -{ - typedarraypool.factory( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` method which returns void... -{ - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.free( arr ); // $ExpectType void -} - -// The compiler throws an error if the `free` method is provided a first argument which is neither a typed array nor array buffer... -{ - typedarraypool.free( true ); // $ExpectError - typedarraypool.free( false ); // $ExpectError - typedarraypool.free( 123 ); // $ExpectError - typedarraypool.free( 'abc' ); // $ExpectError - typedarraypool.free( null ); // $ExpectError - typedarraypool.free( {} ); // $ExpectError - typedarraypool.free( ( x: number ): number => x ); // $ExpectError -} - -// Attached to the main export is a `clear` method which returns void... -{ - typedarraypool.clear(); // $ExpectType void -} - -// The compiler throws an error if the `clear` method is provided arguments... -{ - typedarraypool.clear( {} ); // $ExpectError - typedarraypool.clear( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `highWaterMark` property... -{ - typedarraypool.highWaterMark; // $ExpectType number -} - -// Attached to the main export is a `nbytes` property... -{ - typedarraypool.nbytes; // $ExpectType number -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 24a7846..0000000 --- a/examples/index.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 randu = require( '@stdlib/random-base-randu' ); -var typedarraypool = require( './../lib' ); - -// Create a typed array pool which can allocate at most 1GB: -var typedarray = typedarraypool.factory({ - 'highWaterMark': 1e9 -}); - -// Inspect the pool: -console.log( 'Max bytes: %d', typedarray.highWaterMark ); -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Allocate an array for storing double-precision floating-point numbers: -var arr1 = typedarray( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Fill the array... -var i; -for ( i = 0; i < arr1.length; i++ ) { - arr1[ i ] = randu(); -} - -// Inspect array contents: -console.log( arr1 ); - -// Free the array: -typedarray.free( arr1 ); - -// Allocate another array similar to the previous one: -var arr2 = typedarray( 5, 'float64' ); -// returns - -// Check that we have been returned a new typed array view: -console.log( arr2 === arr1 ); -// => false - -// Inspect array contents: -console.log( arr2 ); - -// Free the array: -typedarray.free( arr2 ); - -// Allocate an initialized array: -var arr3 = typedarray.calloc( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect array contents: -console.log( arr3 ); - -// Free the array: -typedarray.free( arr3 ); - -// Clear the pool: -typedarray.clear(); - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 4254ef5..0f5442f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike, RealOrComplexTypedArray, NumericDataType as DataType } from '@stdlib/types/array'; import ArrayBuffer = require( '@stdlib/array-buffer' ); diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..3b64ba8 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessors@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-defaults@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.1.1-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.1.0-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.1.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.1.1-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";function M(e,t){return w(t)?k(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(j("invalid option. `%s` option must be a nonnegative integer. Option: `%s`.","highWaterMark",e.highWaterMark)):null:new TypeError(j("invalid argument. Options argument must be an object. Value: `%s`.",t))}function W(e){var t,r;for(t=[],r=0;rV.highWaterMark?null:(t=new v(e),w+=e,t)}function F(e,t,r){var s;return 0===t?new e(0):null===(s=B(b(t)*E[r]))?s:new e(s,0,t)}function P(){var e,n,i,m,c,v,u,g,b;if(n=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:T,null===(i=d(n)))throw new TypeError(j("invalid argument. Must provide a recognized data type. Value: `%s`.",n));if(e<=0)return new i(0);if(r(arguments[0]))return F(i,arguments[0],n);if(s(arguments[0])){if(g=(m=arguments[0]).length,o(m)?m=h(m,0):a(m)?m=l(m,0):/^complex/.test(n)&&(g/=2),null===(c=F(i,g,n)))return c;if(z(c)||O(c))return c.set(m),c;for(u=p(f(m)).accessors[0],v=p(n).accessors[1],b=0;b0){for(t=g(x(e.byteLength)),t=y(k.length-1,t),r=k[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = accessors( adtype( arr ) ).accessors[ 0 ];\n\t\t\tset = accessors( dtype ).accessors[ 1 ];\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","DEFAULT_DTYPE","ARRAY_DEFAULTS","get","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","accessors","adtype","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;y1EAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,2EAA4E,gBAAiBP,EAAKI,gBAG3H,KARC,IAAIE,UAAWC,EAAQ,qEAAsEN,GAStG,CC/BA,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,iHCcIG,EAAgBC,EAAeC,IAAK,kBACpCC,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASrB,GACjB,IAAIsB,EACAf,EACAR,EACAwB,EAGJ,GADAxB,ECjFO,CACNI,cAAiB,kBDiFbqB,UAAUC,SACdF,EAAMzB,EAAUC,EAAMC,IAErB,MAAMuB,EAaR,OAVAhB,EAAOmB,EAAYC,EAAMC,EAAM7B,EAAKI,iBACpCmB,EAAS,EAETO,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB/B,EAAKI,eAC3C+B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOb,CACP,CASD,SAASc,EAAa5B,GACrB,IAAI6B,EACA3B,EAMJ,OAHAA,EAAIkB,EAAMpB,IAGDD,EAAKkB,QAAUlB,EAAMG,GAAIe,OAC1BlB,EAAMG,GAAI4B,MAGbhB,EAAOd,EAAIT,EAAKI,cACb,MAERkC,EAAM,IAAIE,EAAa/B,GAGvBc,GAAUd,EAEH6B,EACP,CAWD,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,EACzB,CAkBD,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAtB,EACAV,EACAsC,EACAjC,EACA4B,EACAhC,EAUJ,GALCiC,GAHDG,EAAQtB,UAAUC,SACJuB,EAAUxB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGDlC,EAGK,QADd6B,EAAOzB,EAAO2B,IAEb,MAAM,IAAItC,UAAWC,EAAQ,sEAAuEqC,IAErG,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKrC,EAAsBoB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKM,EAAczB,UAAW,IAAQ,CAYrC,GAVAkB,GADAvB,EAAMK,UAAW,IACPC,OACLyB,EAAmB/B,GACvBA,EAAMgC,EAAgBhC,EAAK,GAChBiC,EAAkBjC,GAC7BA,EAAMkC,EAAelC,EAAK,GACf,WAAWmC,KAAMX,KAE5BD,GAAO,GAGK,QADbjC,EAAM+B,EAAYC,EAAMC,EAAKC,IAE5B,OAAOlC,EAER,GAAKW,EAAiBX,IAASS,EAAgBT,GAE9C,OADAA,EAAIsC,IAAK5B,GACFV,EAKR,IAFAK,EAAMyC,EAAWC,EAAQrC,IAAQoC,UAAW,GAC5CR,EAAMQ,EAAWZ,GAAQY,UAAW,GAC9B7C,EAAI,EAAGA,EAAIgC,EAAKhC,IACrBqC,EAAKtC,EAAKC,EAAGI,EAAKK,EAAKT,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,wGAAyGkB,UAAW,IACjJ,CAgBD,SAASO,IACR,IAAIe,EACArC,EACAgD,EACA/C,EAUJ,GAAa,QANZD,EADc,KADfqC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCiC,EADIrC,EAAiBX,GACf0C,EAAgB1C,EAAK,GAChBS,EAAgBT,GACrB4C,EAAe5C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAI+C,EAAIhC,OAAQf,IAC5B+C,EAAK/C,GAAM,EAGb,OAAOD,CACP,CAcD,SAASuB,EAAMK,GACd,IAAI7B,EACAkD,EACAhD,EACJ,GAAKiD,EAAkBtB,IAASA,EAAIuB,OACnCvB,EAAMA,EAAIuB,YACJ,IAAMC,EAAexB,GAC3B,MAAM,IAAIhC,UAAWC,EAAQ,4EAA6E+B,IAE3G,GAAKA,EAAIyB,WAAa,EAAI,CAQzB,IAPAtD,EAAIuD,EAAOnC,EAAMS,EAAIyB,aAGrBtD,EAAIwD,EAAKzD,EAAKkB,OAAO,EAAGjB,GAGxBkD,EAAInD,EAAMC,GACJE,EAAI,EAAGA,EAAIgD,EAAEjC,OAAQf,IAC1B,GAAKgD,EAAGhD,KAAQ2B,EACf,OAAO,EAITqB,EAAE/C,KAAM0B,EACR,CACD,OAAO,CACP,CAOD,SAASJ,IACR,IAAIvB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKkB,OAAQf,IAC7BH,EAAMG,GAAIe,OAAS,EAEpBH,EAAS,CACT,CACF,CErTG,IAAC2C,EAAiB5C,ICPrBQ,EAAAqC,EAAA,UAAA7C"} \ No newline at end of file diff --git a/lib/bytes_per_element.json b/lib/bytes_per_element.json deleted file mode 100644 index f97fe70..0000000 --- a/lib/bytes_per_element.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "float64": 8, - "float32": 4, - "int16": 2, - "int32": 4, - "int8": 1, - "uint16": 2, - "uint32": 4, - "uint8": 1, - "uint8c": 1, - "complex64": 8, - "complex128": 16 -} diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index a421711..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +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'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'highWaterMark': 9007199254740992 - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 662f213..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,372 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var isComplex64Array = require( '@stdlib/assert-is-complex64array' ); -var isComplex128Array = require( '@stdlib/assert-is-complex128array' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var ctors = require( '@stdlib/array-typed-ctors' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var accessors = require( '@stdlib/array-base-accessors' ); -var adtype = require( '@stdlib/array-dtype' ); -var ARRAY_DEFAULTS = require( '@stdlib/array-defaults' ); -var format = require( '@stdlib/string-format' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil = require( '@stdlib/math-base-special-ceil' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); -var log2 = require( '@stdlib/math-base-special-log2' ); -var min = require( '@stdlib/math-base-special-min' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var createPool = require( './pool.js' ); -var BYTES_PER_ELEMENT = require( './bytes_per_element.json' ); - - -// VARIABLES // - -var DEFAULT_DTYPE = ARRAY_DEFAULTS.get( 'dtypes.default' ); -var Complex64Array = ctors( 'complex64' ); -var Complex128Array = ctors( 'complex128' ); - - -// FUNCTIONS // - -/** -* Tests whether an array is a single-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a single-precision complex floating-point number array -*/ -function isCmplx64Array( arr ) { - return ( arr instanceof Complex64Array ); -} - -/** -* Tests whether an array is a double-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a double-precision complex floating-point number array -*/ -function isCmplx128Array( arr ) { - return ( arr instanceof Complex128Array ); -} - - -// MAIN // - -/** -* Creates a typed array pool. -* -* @param {Options} [options] - pool options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} allocator -* -* @example -* var typedarraypool = factory(); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -function factory( options ) { - var nbytes; - var pool; - var opts; - var err; - - opts = defaults(); - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - pool = createPool( ceil( log2( opts.highWaterMark ) ) ); - nbytes = 0; - - setReadOnly( malloc, 'malloc', malloc ); // circular reference - setReadOnly( malloc, 'calloc', calloc ); - setReadOnly( malloc, 'free', free ); - setReadOnly( malloc, 'clear', clear ); - setReadOnly( malloc, 'highWaterMark', opts.highWaterMark ); - setReadOnlyAccessor( malloc, 'nbytes', getBytes ); - - return malloc; - - /** - * Returns the number of allocated bytes. - * - * @private - * @returns {NonNegativeInteger} number of allocated bytes - */ - function getBytes() { - return nbytes; - } - - /** - * Returns an array buffer. - * - * @private - * @param {NonNegativeInteger} n - number of bytes - * @returns {(ArrayBuffer|null)} array buffer or null - */ - function arraybuffer( n ) { - var buf; - var i; - - // Convert the number of bytes to an index in our pool table: - i = log2( n ); - - // If we already have an available array buffer, use it... - if ( i < pool.length && pool[ i ].length ) { - return pool[ i ].pop(); - } - // Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate... - if ( nbytes+n > opts.highWaterMark ) { - return null; - } - buf = new ArrayBuffer( n ); - - // Update the running counter of allocated bytes: - nbytes += n; - - return buf; - } - - /** - * Returns a typed array. - * - * @private - * @param {Function} ctor - typed array constructor - * @param {NonNegativeInteger} len - view length - * @param {string} dtype - data type - * @returns {(TypedArray|null)} typed array or null - */ - function typedarray( ctor, len, dtype ) { - var buf; - if ( len === 0 ) { - return new ctor( 0 ); - } - buf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] ); - if ( buf === null ) { - return buf; - } - return new ctor( buf, 0, len ); - } - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length or an array-like object - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function malloc() { - var nargs; - var dtype; - var ctor; - var arr; - var out; - var set; - var get; - var len; - var i; - - nargs = arguments.length; - if ( nargs && isString( arguments[ nargs-1 ] ) ) { - nargs -= 1; - dtype = arguments[ nargs ]; - } else { - dtype = DEFAULT_DTYPE; - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) ); - } - if ( nargs <= 0 ) { - return new ctor( 0 ); - } - // Check if provided a typed array length... - if ( isNonNegativeInteger( arguments[ 0 ] ) ) { - return typedarray( ctor, arguments[ 0 ], dtype ); - } - // Check if provided an array-like object containing data elements... - if ( isCollection( arguments[ 0 ] ) ) { - arr = arguments[ 0 ]; - len = arr.length; - if ( isComplex128Array( arr ) ) { - arr = reinterpret128( arr, 0 ); - } else if ( isComplex64Array( arr ) ) { - arr = reinterpret64( arr, 0 ); - } else if ( /^complex/.test( dtype ) ) { - // Assume we've been provided an array of interleaved real and imaginary components... - len /= 2; - } - out = typedarray( ctor, len, dtype ); - if ( out === null ) { - return out; - } - if ( isCmplx128Array( out ) || isCmplx64Array( out ) ) { - out.set( arr ); - return out; - } - // Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other "unsafe" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things... - get = accessors( adtype( arr ) ).accessors[ 0 ]; - set = accessors( dtype ).accessors[ 1 ]; - for ( i = 0; i < len; i++ ) { - set( out, i, get( arr, i ) ); - } - return out; - } - throw new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) ); - } - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {NonNegativeInteger} [len=0] - array length - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function calloc() { - var nargs; - var out; - var tmp; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - out = malloc(); - } else if ( nargs === 1 ) { - out = malloc( arguments[ 0 ] ); - } else { - out = malloc( arguments[ 0 ], arguments[ 1 ] ); - } - if ( out !== null ) { - // Initialize the memory... - if ( isCmplx128Array( out ) ) { - tmp = reinterpret128( out, 0 ); - } else if ( isCmplx64Array( out ) ) { - tmp = reinterpret64( out, 0 ); - } else { - tmp = out; - } - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = 0.0; - } - } - return out; - } - - /** - * Frees a typed array or typed array buffer. - * - * ## Notes - * - * - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., "freeing" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool. - * - * @private - * @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free - * @throws {TypeError} must provide a typed array or typed array buffer - * @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed - */ - function free( buf ) { - var n; - var p; - var i; - if ( isTypedArrayLike( buf ) && buf.buffer ) { - buf = buf.buffer; - } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) ); - } - if ( buf.byteLength > 0 ) { - n = floor( log2( buf.byteLength ) ); - - // Prohibit "freeing" array buffers which would potentially allow users to circumvent high water mark limits: - n = min( pool.length-1, n ); - - // Ensure that we do not attempt to free the same buffer more than once... - p = pool[ n ]; - for ( i = 0; i < p.length; i++ ) { - if ( p[ i ] === buf ) { - return false; - } - } - // Add the buffer to our pool of free buffers: - p.push( buf ); - } - return true; - } - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @private - */ - function clear() { - var i; - for ( i = 0; i < pool.length; i++ ) { - pool[ i ].length = 0; - } - nbytes = 0; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6c12a4e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Typed array pool. -* -* @module @stdlib/array-pool -* -* @example -* var typedarraypool = require( '@stdlib/array-pool' ); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8f69ee3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,63 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @name typedarraypool -* @type {Function} -* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a valid array length or an array-like object -* @throws {TypeError} must provide a recognized data type -* @returns {(TypedArray|null)} typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -var typedarraypool = factory(); - - -// EXPORTS // - -module.exports = typedarraypool; diff --git a/lib/pool.js b/lib/pool.js deleted file mode 100644 index 5abd287..0000000 --- a/lib/pool.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Initializes a cache for pooled typed array buffers. -* -* @private -* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size -* @returns {ArrayArray} initialized cache -*/ -function pool( n ) { - var out; - var i; - - out = []; - for ( i = 0; i < n+1; i++ ) { - out.push( [] ); - } - return out; -} - - -// EXPORTS // - -module.exports = pool; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index ce54890..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'highWaterMark': 1024 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'highWaterMark' ) ) { - opts.highWaterMark = options.highWaterMark; - if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index bf25163..bd7b179 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Typed array pool.", "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,77 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-accessors": "^0.1.0", - "@stdlib/array-buffer": "^0.1.0", - "@stdlib/array-defaults": "^0.1.0", - "@stdlib/array-dtype": "^0.1.0", - "@stdlib/array-typed-ctors": "^0.1.0", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-arraybuffer": "^0.1.1", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-complex128array": "^0.1.0", - "@stdlib/assert-is-complex64array": "^0.1.0", - "@stdlib/assert-is-nonnegative-integer": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/assert-is-string": "^0.1.1", - "@stdlib/assert-is-typed-array-like": "^0.1.0", - "@stdlib/math-base-special-ceil": "^0.1.1", - "@stdlib/math-base-special-ceil2": "^0.1.0", - "@stdlib/math-base-special-floor": "^0.1.1", - "@stdlib/math-base-special-log2": "^0.1.1", - "@stdlib/math-base-special-min": "^0.1.1", - "@stdlib/strided-base-reinterpret-complex128": "^0.1.1", - "@stdlib/strided-base-reinterpret-complex64": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.1.0", - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-float32": "^0.1.1", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/array-int16": "^0.1.1", - "@stdlib/array-int32": "^0.1.1", - "@stdlib/array-int8": "^0.1.1", - "@stdlib/array-uint16": "^0.1.1", - "@stdlib/array-uint32": "^0.1.1", - "@stdlib/array-uint8": "^0.1.1", - "@stdlib/array-uint8c": "^0.1.1", - "@stdlib/assert-instance-of": "^0.1.1", - "@stdlib/assert-is-complex-typed-array": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-typed-array": "^0.1.0", - "@stdlib/complex-float32": "^0.1.1", - "@stdlib/complex-float64": "^0.1.1", - "@stdlib/complex-imag": "^0.1.1", - "@stdlib/complex-imagf": "^0.1.1", - "@stdlib/complex-real": "^0.1.1", - "@stdlib/complex-realf": "^0.1.1", - "@stdlib/math-base-special-pow": "^0.1.0", - "@stdlib/random-base-randu": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..afdd3d6 --- /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.factory.js b/test/test.factory.js deleted file mode 100644 index 396aee2..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,2240 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function (no options)', function test( t ) { - t.strictEqual( typeof factory(), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - t.strictEqual( typeof factory( {} ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided a `highWaterMark` option which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (length)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a function which returns a typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, length)', function test( t ) { - var typedarraypool = factory(); - var arr; - - arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a `malloc` method which is a circular reference', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - var buf; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the returned function is a property which returns the pool\'s high water mark', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function supports specifying a high water mark which limits the total amount of memory a pool can allocate', function test( t ) { - var typedarraypool; - var arr1; - var arr2; - - typedarraypool = factory({ - 'highWaterMark': 64 // bytes - }); - - typedarraypool.clear(); - - arr1 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr1.length, 8, 'returns expected value' ); - t.strictEqual( arr1.byteLength, 64, 'returns expected value' ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - typedarraypool.free( arr1 ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Create an array which is less than or equal to the high water mark: - arr2 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr2.length, 8, 'returns expected value' ); - t.strictEqual( arr2.byteLength, 64, 'returns expected value' ); - - typedarraypool.free( arr2 ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a property which returns the total number of accumulated bytes', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var typedarraypool; - var arrs; - var i; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 54aa5ee..0000000 --- a/test/test.js +++ /dev/null @@ -1,1797 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var typedarraypool = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -}); From 91ad5fe0995311532d1a57456ac7a018070c9857 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 6 Feb 2024 02:55:28 +0000 Subject: [PATCH 064/103] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 83f57e7..5de5f4f 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "@stdlib/math-base-special-min": "^0.1.1", "@stdlib/strided-base-reinterpret-complex128": "^0.1.1", "@stdlib/strided-base-reinterpret-complex64": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.3.1", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" From 0c19ff14fd7cfb9a88448a46d332fb00aec83a35 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 6 Feb 2024 03:03:32 +0000 Subject: [PATCH 065/103] Remove files --- index.d.ts | 359 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6541 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 0f5442f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,359 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike, RealOrComplexTypedArray, NumericDataType as DataType } from '@stdlib/types/array'; -import ArrayBuffer = require( '@stdlib/array-buffer' ); - -/** -* Typed array or null. -*/ -type TypedArrayOrNull = RealOrComplexTypedArray | null; - -/** -* Interface defining pool options. -*/ -interface Options { - /** - * Maximum total memory which can be allocated. - */ - highWaterMark?: number; -} - -/** -* Pool interface. -*/ -interface Pool { - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr = typedarraypool(); - * // returns [] - * - * @example - * var arr = typedarraypool( 'float32' ); - * // returns [] - */ - ( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * // Allocate an array of doubles: - * var arr = typedarraypool( 5, 'float64' ); - * // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * typedarraypool.free( arr ); - * - * @example - * var arr1 = typedarraypool( [ 0.5, 0.5, 0.5 ] ); - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * @example - * var arr1 = [ 0.5, 0.5, 0.5 ]; - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - */ - ( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc(); - * // returns [] - * - * var arr2 = typedarraypool.calloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param length - typed array length - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc( 5 ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * var arr2 = typedarraypool.calloc( 5, 'uint8' ); - * // returns [ 0, 0, 0, 0, 0 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( length: number, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc(); - * // returns [] - * - * var arr2 = typedarraypool.malloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc( 5 ); - * // returns - * - * var arr2 = typedarraypool.malloc( 5, 'uint8' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 5.0, -3.0, 2.0 ] ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr2 = typedarraypool.malloc( arr1 ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr3 = typedarraypool.malloc( arr1, 'int32' ); - * // returns [ 5, -3, 2 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * typedarraypool.free( arr3 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ] ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * var arr2 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ], 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Frees a typed array or typed array buffer for use in a future allocation. - * - * @param buf - typed array or typed array buffer to free - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array for use in a future allocation: - * typedarraypool.free( arr ); - * - * // Create another typed array: - * arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array buffer for use in a future allocation: - * typedarraypool.free( arr.buffer ); - */ - free( buf: RealOrComplexTypedArray | ArrayBuffer ): void; - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr ); - * - * // ... - * - * // Clear all freed buffers: - * typedarraypool.clear(); - */ - clear(): void; - - /** - * Read-only property returning the pool's high water mark. - * - * ## Notes - * - * - Once a high water mark is reached, typed array allocation fails. - * - * @example - * var limit = typedarraypool.highWaterMark; - * // returns - */ - readonly highWaterMark: number; - - /** - * Read-only property returning the total number of allocated bytes. - * - * @example - * var arr = typedarraypool( 5, 'float64' ); - * - * var nbytes = typedarraypool.nbytes; - * // returns - */ - readonly nbytes: number; - - /** - * Creates a typed array pool. - * - * @param options - pool options - * @param options.highWaterMark - maximum total memory which can be allocated - * @throws must provide valid options - * @returns allocator - * - * @example - * var allocator = typedarraypool.factory(); - * - * // Allocate an array of doubles: - * var arr = allocator( 5, 'float64' ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * allocator.free( arr ); - */ - factory( options?: Options ): Pool; -} - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @param arg - an array length or an array-like object -* @param dtype - data type (default: 'float64') -* @returns typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -declare var typedarraypool: Pool; - - -// EXPORTS // - -export = typedarraypool; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 3b64ba8..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-accessors@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-dtype@v0.1.0-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-defaults@v0.1.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.1.1-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.1.0-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.1.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.1.1-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";function M(e,t){return w(t)?k(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(j("invalid option. `%s` option must be a nonnegative integer. Option: `%s`.","highWaterMark",e.highWaterMark)):null:new TypeError(j("invalid argument. Options argument must be an object. Value: `%s`.",t))}function W(e){var t,r;for(t=[],r=0;rV.highWaterMark?null:(t=new v(e),w+=e,t)}function F(e,t,r){var s;return 0===t?new e(0):null===(s=B(b(t)*E[r]))?s:new e(s,0,t)}function P(){var e,n,i,m,c,v,u,g,b;if(n=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:T,null===(i=d(n)))throw new TypeError(j("invalid argument. Must provide a recognized data type. Value: `%s`.",n));if(e<=0)return new i(0);if(r(arguments[0]))return F(i,arguments[0],n);if(s(arguments[0])){if(g=(m=arguments[0]).length,o(m)?m=h(m,0):a(m)?m=l(m,0):/^complex/.test(n)&&(g/=2),null===(c=F(i,g,n)))return c;if(z(c)||O(c))return c.set(m),c;for(u=p(f(m)).accessors[0],v=p(n).accessors[1],b=0;b0){for(t=g(x(e.byteLength)),t=y(k.length-1,t),r=k[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Wrap the arrays in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = accessors( adtype( arr ) ).accessors[ 0 ];\n\t\t\tset = accessors( dtype ).accessors[ 1 ];\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","DEFAULT_DTYPE","ARRAY_DEFAULTS","get","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","accessors","adtype","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;y1EAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,2EAA4E,gBAAiBP,EAAKI,gBAG3H,KARC,IAAIE,UAAWC,EAAQ,qEAAsEN,GAStG,CC/BA,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,iHCcIG,EAAgBC,EAAeC,IAAK,kBACpCC,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASrB,GACjB,IAAIsB,EACAf,EACAR,EACAwB,EAGJ,GADAxB,ECjFO,CACNI,cAAiB,kBDiFbqB,UAAUC,SACdF,EAAMzB,EAAUC,EAAMC,IAErB,MAAMuB,EAaR,OAVAhB,EAAOmB,EAAYC,EAAMC,EAAM7B,EAAKI,iBACpCmB,EAAS,EAETO,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB/B,EAAKI,eAC3C+B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOb,CACP,CASD,SAASc,EAAa5B,GACrB,IAAI6B,EACA3B,EAMJ,OAHAA,EAAIkB,EAAMpB,IAGDD,EAAKkB,QAAUlB,EAAMG,GAAIe,OAC1BlB,EAAMG,GAAI4B,MAGbhB,EAAOd,EAAIT,EAAKI,cACb,MAERkC,EAAM,IAAIE,EAAa/B,GAGvBc,GAAUd,EAEH6B,EACP,CAWD,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,EACzB,CAkBD,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAtB,EACAV,EACAsC,EACAjC,EACA4B,EACAhC,EAUJ,GALCiC,GAHDG,EAAQtB,UAAUC,SACJuB,EAAUxB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGDlC,EAGK,QADd6B,EAAOzB,EAAO2B,IAEb,MAAM,IAAItC,UAAWC,EAAQ,sEAAuEqC,IAErG,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKrC,EAAsBoB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKM,EAAczB,UAAW,IAAQ,CAYrC,GAVAkB,GADAvB,EAAMK,UAAW,IACPC,OACLyB,EAAmB/B,GACvBA,EAAMgC,EAAgBhC,EAAK,GAChBiC,EAAkBjC,GAC7BA,EAAMkC,EAAelC,EAAK,GACf,WAAWmC,KAAMX,KAE5BD,GAAO,GAGK,QADbjC,EAAM+B,EAAYC,EAAMC,EAAKC,IAE5B,OAAOlC,EAER,GAAKW,EAAiBX,IAASS,EAAgBT,GAE9C,OADAA,EAAIsC,IAAK5B,GACFV,EAKR,IAFAK,EAAMyC,EAAWC,EAAQrC,IAAQoC,UAAW,GAC5CR,EAAMQ,EAAWZ,GAAQY,UAAW,GAC9B7C,EAAI,EAAGA,EAAIgC,EAAKhC,IACrBqC,EAAKtC,EAAKC,EAAGI,EAAKK,EAAKT,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,wGAAyGkB,UAAW,IACjJ,CAgBD,SAASO,IACR,IAAIe,EACArC,EACAgD,EACA/C,EAUJ,GAAa,QANZD,EADc,KADfqC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCiC,EADIrC,EAAiBX,GACf0C,EAAgB1C,EAAK,GAChBS,EAAgBT,GACrB4C,EAAe5C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAI+C,EAAIhC,OAAQf,IAC5B+C,EAAK/C,GAAM,EAGb,OAAOD,CACP,CAcD,SAASuB,EAAMK,GACd,IAAI7B,EACAkD,EACAhD,EACJ,GAAKiD,EAAkBtB,IAASA,EAAIuB,OACnCvB,EAAMA,EAAIuB,YACJ,IAAMC,EAAexB,GAC3B,MAAM,IAAIhC,UAAWC,EAAQ,4EAA6E+B,IAE3G,GAAKA,EAAIyB,WAAa,EAAI,CAQzB,IAPAtD,EAAIuD,EAAOnC,EAAMS,EAAIyB,aAGrBtD,EAAIwD,EAAKzD,EAAKkB,OAAO,EAAGjB,GAGxBkD,EAAInD,EAAMC,GACJE,EAAI,EAAGA,EAAIgD,EAAEjC,OAAQf,IAC1B,GAAKgD,EAAGhD,KAAQ2B,EACf,OAAO,EAITqB,EAAE/C,KAAM0B,EACR,CACD,OAAO,CACP,CAOD,SAASJ,IACR,IAAIvB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKkB,OAAQf,IAC7BH,EAAMG,GAAIe,OAAS,EAEpBH,EAAS,CACT,CACF,CErTG,IAAC2C,EAAiB5C,ICPrBQ,EAAAqC,EAAA,UAAA7C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index afdd3d6..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From b67e8d9b19918f98474c72f22158edbbca5bb614 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 6 Feb 2024 03:04:19 +0000 Subject: [PATCH 066/103] 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 | 45 +- SECURITY.md | 5 - benchmark/benchmark.calloc.js | 246 - benchmark/benchmark.factory.js | 71 - benchmark/benchmark.js | 246 - benchmark/benchmark.length.complex128.js | 102 - benchmark/benchmark.length.complex64.js | 102 - benchmark/benchmark.length.float32.js | 102 - benchmark/benchmark.length.float64.js | 102 - benchmark/benchmark.length.int16.js | 102 - benchmark/benchmark.length.int32.js | 102 - benchmark/benchmark.length.int8.js | 102 - benchmark/benchmark.length.uint16.js | 102 - benchmark/benchmark.length.uint32.js | 102 - benchmark/benchmark.length.uint8.js | 102 - benchmark/benchmark.length.uint8c.js | 102 - benchmark/benchmark.malloc.js | 246 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 347 -- docs/types/test.ts | 193 - examples/index.js | 80 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/bytes_per_element.json | 13 - lib/defaults.js | 42 - lib/factory.js | 372 -- lib/index.js | 56 - lib/main.js | 63 - lib/pool.js | 44 - lib/validate.js | 66 - package.json | 98 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 2240 -------- test/test.js | 1797 ------ 62 files changed, 6206 insertions(+), 10650 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.calloc.js delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.complex128.js delete mode 100644 benchmark/benchmark.length.complex64.js delete mode 100644 benchmark/benchmark.length.float32.js delete mode 100644 benchmark/benchmark.length.float64.js delete mode 100644 benchmark/benchmark.length.int16.js delete mode 100644 benchmark/benchmark.length.int32.js delete mode 100644 benchmark/benchmark.length.int8.js delete mode 100644 benchmark/benchmark.length.uint16.js delete mode 100644 benchmark/benchmark.length.uint32.js delete mode 100644 benchmark/benchmark.length.uint8.js delete mode 100644 benchmark/benchmark.length.uint8c.js delete mode 100644 benchmark/benchmark.malloc.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/bytes_per_element.json delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/pool.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ea35f20..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/array/pool) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6f7c875..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/array/pool) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 beada65..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -495,7 +492,7 @@ console.log( 'nbytes: %d', typedarray.nbytes ); ## 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]. @@ -564,7 +561,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/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.calloc.js b/benchmark/benchmark.calloc.js deleted file mode 100644 index fd8f53d..0000000 --- a/benchmark/benchmark.calloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':calloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 58918bb..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = typedarray.factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:highWaterMark', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'highWaterMark': 0 - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.highWaterMark = i; - f = typedarray.factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 4310559..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.complex128.js b/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 12c6668..0000000 --- a/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex64.js b/benchmark/benchmark.length.complex64.js deleted file mode 100644 index ca2b45c..0000000 --- a/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float32.js b/benchmark/benchmark.length.float32.js deleted file mode 100644 index b3b4508..0000000 --- a/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float64.js b/benchmark/benchmark.length.float64.js deleted file mode 100644 index 5f0132d..0000000 --- a/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int16.js b/benchmark/benchmark.length.int16.js deleted file mode 100644 index 9f253cb..0000000 --- a/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int32.js b/benchmark/benchmark.length.int32.js deleted file mode 100644 index f83e795..0000000 --- a/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int8.js b/benchmark/benchmark.length.int8.js deleted file mode 100644 index 5b01174..0000000 --- a/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint16.js b/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 32b0a5d..0000000 --- a/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint32.js b/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 290b90c..0000000 --- a/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8.js b/benchmark/benchmark.length.uint8.js deleted file mode 100644 index ff7d733..0000000 --- a/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8c.js b/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index 8f0d10a..0000000 --- a/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.malloc.js b/benchmark/benchmark.malloc.js deleted file mode 100644 index 1661907..0000000 --- a/benchmark/benchmark.malloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':malloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 612de17..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/array/pool" -%% click B href "https://github.com/stdlib-js/array-pool/tree/main" -%% click C href "https://github.com/stdlib-js/array-pool/tree/production" -%% click D href "https://github.com/stdlib-js/array-pool/tree/esm" -%% click E href "https://github.com/stdlib-js/array-pool/tree/deno" -%% click F href "https://github.com/stdlib-js/array-pool/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/pool -[production-url]: https://github.com/stdlib-js/array-pool/tree/production -[deno-url]: https://github.com/stdlib-js/array-pool/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-pool/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-pool/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-pool/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-pool/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-pool/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 5160b6f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import typedarraypool from '../docs/types/index'; -export = typedarraypool; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4f5b474..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var l=function(n,i){return function(){return i||n((i={exports:{}}).exports,i),i.exports}};var M=l(function(Er,w){ -function I(){return{highWaterMark:9007199254740992}}w.exports=I -});var T=l(function(Tr,E){ -var U=require('@stdlib/assert-is-plain-object/dist'),z=require('@stdlib/assert-has-own-property/dist'),G=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,k=require('@stdlib/error-tools-fmtprodmsg/dist');function H(n,i){return U(i)?z(i,"highWaterMark")&&(n.highWaterMark=i.highWaterMark,!G(n.highWaterMark))?new TypeError(k('01H2t',"highWaterMark",n.highWaterMark)):null:new TypeError(k('01H2V',i));}E.exports=H -});var C=l(function(Wr,W){ -function J(n){var i,u;for(i=[],u=0;uv.highWaterMark?null:(e=new or(r),i+=r,e)}function d(r,e,a){var t;return e===0?new r(0):(t=j(vr(e)*mr[a]),t===null?t:new r(t,0,e))}function o(){var r,e,a,t,s,x,A,c,f;if(r=arguments.length,r&&Q(arguments[r-1])?(r-=1,e=arguments[r]):e=pr,a=y(e),a===null)throw new TypeError(m('01H2Y',e));if(r<=0)return new a(0);if(X(arguments[0]))return d(a,arguments[0],e);if(Z(arguments[0])){if(t=arguments[0],c=t.length,tr(t)?t=b(t,0):er(t)?t=P(t,0):/^complex/.test(e)&&(c/=2),s=d(a,c,e),s===null)return s;if(R(s)||L(s))return s.set(t),s;for(A=ir(t),x=nr(s),f=0;f0){for(e=lr(p(r.byteLength)),e=fr(u.length-1,e),a=u[e],t=0;t[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = resolveGetter( arr );\n\t\t\tset = resolveSetter( out );\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nmodule.exports = typedarraypool;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* var typedarraypool = require( '@stdlib/array-pool' );\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,cAAiB,gBAClB,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,eAAgB,IACzCD,EAAK,cAAgBC,EAAQ,cACxB,CAACJ,EAAsBG,EAAK,aAAc,GACvC,IAAI,UAAWF,EAAQ,2EAA4E,gBAAiBE,EAAK,aAAc,CAAE,EAG3I,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cA6BA,SAASC,EAAM,EAAI,CAClB,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAI,EAAE,EAAGA,IACrBD,EAAI,KAAM,CAAC,CAAE,EAEd,OAAOA,CACR,CAKAF,EAAO,QAAUC,IC3CjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,QAAW,EACX,QAAW,EACX,MAAS,EACT,MAAS,EACT,KAAQ,EACR,OAAU,EACV,OAAU,EACV,MAAS,EACT,OAAU,EACT,UAAa,EACb,WAAc,EAChB,ICZA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAe,QAAS,8BAA+B,EACvDC,EAAmB,QAAS,oCAAqC,EACjEC,GAAgB,QAAS,+BAAgC,EACzDC,GAAmB,QAAS,kCAAmC,EAC/DC,GAAoB,QAAS,mCAAoC,EACjEC,EAAc,QAAS,uDAAwD,EAC/EC,GAAsB,QAAS,uDAAwD,EACvFC,EAAQ,QAAS,2BAA4B,EAC7CC,EAAgB,QAAS,4CAA6C,EACtEC,EAAiB,QAAS,6CAA8C,EACxEC,GAAgB,QAAS,mCAAoC,EAC7DC,GAAgB,QAAS,mCAAoC,EAC7DC,GAAiB,QAAS,wBAAyB,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,GAAc,QAAS,sBAAuB,EAC9CC,GAAO,QAAS,gCAAiC,EACjDC,GAAQ,QAAS,iCAAkC,EACnDC,GAAQ,QAAS,iCAAkC,EACnDC,EAAO,QAAS,gCAAiC,EACjDC,GAAM,QAAS,+BAAgC,EAC/CC,GAAW,IACXC,GAAW,IACXC,GAAa,IACbC,GAAoB,IAKpBC,GAAgBZ,GAAe,IAAK,gBAAiB,EACrDa,GAAiBlB,EAAO,WAAY,EACpCmB,GAAkBnB,EAAO,YAAa,EAY1C,SAASoB,EAAgBC,EAAM,CAC9B,OAASA,aAAeH,EACzB,CASA,SAASI,EAAiBD,EAAM,CAC/B,OAASA,aAAeF,EACzB,CA6BA,SAASI,GAASC,EAAU,CAC3B,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,EAAOd,GAAS,EACX,UAAU,SACde,EAAMd,GAAUa,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAAF,EAAOX,GAAYP,GAAMG,EAAMgB,EAAK,aAAc,CAAE,CAAE,EACtDF,EAAS,EAET3B,EAAa+B,EAAQ,SAAUA,CAAO,EACtC/B,EAAa+B,EAAQ,SAAUC,CAAO,EACtChC,EAAa+B,EAAQ,OAAQE,CAAK,EAClCjC,EAAa+B,EAAQ,QAASG,CAAM,EACpClC,EAAa+B,EAAQ,gBAAiBF,EAAK,aAAc,EACzD5B,GAAqB8B,EAAQ,SAAUI,CAAS,EAEzCJ,EAQP,SAASI,GAAW,CACnB,OAAOR,CACR,CASA,SAASS,EAAaC,EAAI,CACzB,IAAIC,EACAC,EAMJ,OAHAA,EAAI1B,EAAMwB,CAAE,EAGPE,EAAIX,EAAK,QAAUA,EAAMW,CAAE,EAAE,OAC1BX,EAAMW,CAAE,EAAE,IAAI,EAGjBZ,EAAOU,EAAIR,EAAK,cACb,MAERS,EAAM,IAAI7B,GAAa4B,CAAE,EAGzBV,GAAUU,EAEHC,EACR,CAWA,SAASE,EAAYC,EAAMC,EAAKC,EAAQ,CACvC,IAAIL,EACJ,OAAKI,IAAQ,EACL,IAAID,EAAM,CAAE,GAEpBH,EAAMF,EAAaxB,GAAO8B,CAAI,EAAExB,GAAmByB,CAAM,CAAE,EACtDL,IAAQ,KACLA,EAED,IAAIG,EAAMH,EAAK,EAAGI,CAAI,EAC9B,CAkBA,SAASX,GAAS,CACjB,IAAIa,EACAD,EACAF,EACAlB,EACAsB,EACAC,EACAC,EACAL,EACAH,EAUJ,GARAK,EAAQ,UAAU,OACbA,GAASnD,EAAU,UAAWmD,EAAM,CAAE,CAAE,GAC5CA,GAAS,EACTD,EAAQ,UAAWC,CAAM,GAEzBD,EAAQxB,GAETsB,EAAOvC,EAAOyC,CAAM,EACfF,IAAS,KACb,MAAM,IAAI,UAAWjC,EAAQ,sEAAuEmC,CAAM,CAAE,EAE7G,GAAKC,GAAS,EACb,OAAO,IAAIH,EAAM,CAAE,EAGpB,GAAK/C,EAAsB,UAAW,CAAE,CAAE,EACzC,OAAO8C,EAAYC,EAAM,UAAW,CAAE,EAAGE,CAAM,EAGhD,GAAKhD,EAAc,UAAW,CAAE,CAAE,EAAI,CAYrC,GAXA4B,EAAM,UAAW,CAAE,EACnBmB,EAAMnB,EAAI,OACLxB,GAAmBwB,CAAI,EAC3BA,EAAMnB,EAAgBmB,EAAK,CAAE,EAClBzB,GAAkByB,CAAI,EACjCA,EAAMpB,EAAeoB,EAAK,CAAE,EACjB,WAAW,KAAMoB,CAAM,IAElCD,GAAO,GAERG,EAAML,EAAYC,EAAMC,EAAKC,CAAM,EAC9BE,IAAQ,KACZ,OAAOA,EAER,GAAKrB,EAAiBqB,CAAI,GAAKvB,EAAgBuB,CAAI,EAClD,OAAAA,EAAI,IAAKtB,CAAI,EACNsB,EAKR,IAFAE,EAAM1C,GAAekB,CAAI,EACzBuB,EAAMxC,GAAeuC,CAAI,EACnBN,EAAI,EAAGA,EAAIG,EAAKH,IACrBO,EAAKD,EAAKN,EAAGQ,EAAKxB,EAAKgB,CAAE,CAAE,EAE5B,OAAOM,CACR,CACA,MAAM,IAAI,UAAWrC,EAAQ,wGAAyG,UAAW,CAAE,CAAE,CAAE,CACxJ,CAgBA,SAASwB,GAAS,CACjB,IAAIY,EACAC,EACAG,EACAT,EAUJ,GARAK,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAMd,EAAO,EACFa,IAAU,EACrBC,EAAMd,EAAQ,UAAW,CAAE,CAAE,EAE7Bc,EAAMd,EAAQ,UAAW,CAAE,EAAG,UAAW,CAAE,CAAE,EAEzCc,IAAQ,KASZ,IAPKrB,EAAiBqB,CAAI,EACzBG,EAAM5C,EAAgByC,EAAK,CAAE,EAClBvB,EAAgBuB,CAAI,EAC/BG,EAAM7C,EAAe0C,EAAK,CAAE,EAE5BG,EAAMH,EAEDN,EAAI,EAAGA,EAAIS,EAAI,OAAQT,IAC5BS,EAAKT,CAAE,EAAI,EAGb,OAAOM,CACR,CAcA,SAASZ,EAAMK,EAAM,CACpB,IAAID,EACAY,EACAV,EACJ,GAAK3C,EAAkB0C,CAAI,GAAKA,EAAI,OACnCA,EAAMA,EAAI,eACC,CAACzC,GAAeyC,CAAI,EAC/B,MAAM,IAAI,UAAW9B,EAAQ,4EAA6E8B,CAAI,CAAE,EAEjH,GAAKA,EAAI,WAAa,EAAI,CAQzB,IAPAD,EAAI1B,GAAOE,EAAMyB,EAAI,UAAW,CAAE,EAGlCD,EAAIvB,GAAKc,EAAK,OAAO,EAAGS,CAAE,EAG1BY,EAAIrB,EAAMS,CAAE,EACNE,EAAI,EAAGA,EAAIU,EAAE,OAAQV,IAC1B,GAAKU,EAAGV,CAAE,IAAMD,EACf,MAAO,GAITW,EAAE,KAAMX,CAAI,CACb,CACA,MAAO,EACR,CAOA,SAASJ,GAAQ,CAChB,IAAIK,EACJ,IAAMA,EAAI,EAAGA,EAAIX,EAAK,OAAQW,IAC7BX,EAAMW,CAAE,EAAE,OAAS,EAEpBZ,EAAS,CACV,CACD,CAKAnC,EAAO,QAAUiC,KCnXjB,IAAAyB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAU,IAmCVC,GAAiBD,GAAQ,EAK7BD,EAAO,QAAUE,KCnBjB,IAAIC,GAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,GAAU,IAKdF,GAAaC,EAAM,UAAWC,EAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isNonNegativeInteger", "format", "validate", "opts", "options", "require_pool", "__commonJSMin", "exports", "module", "pool", "out", "i", "require_bytes_per_element", "__commonJSMin", "exports", "module", "require_factory", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isCollection", "isTypedArrayLike", "isArrayBuffer", "isComplex64Array", "isComplex128Array", "setReadOnly", "setReadOnlyAccessor", "ctors", "reinterpret64", "reinterpret128", "resolveGetter", "resolveSetter", "ARRAY_DEFAULTS", "format", "ArrayBuffer", "ceil", "floor", "ceil2", "log2", "min", "defaults", "validate", "createPool", "BYTES_PER_ELEMENT", "DEFAULT_DTYPE", "Complex64Array", "Complex128Array", "isCmplx64Array", "arr", "isCmplx128Array", "factory", "options", "nbytes", "pool", "opts", "err", "malloc", "calloc", "free", "clear", "getBytes", "arraybuffer", "n", "buf", "i", "typedarray", "ctor", "len", "dtype", "nargs", "out", "set", "get", "tmp", "p", "require_main", "__commonJSMin", "exports", "module", "factory", "typedarraypool", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5244595..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,347 +0,0 @@ - -{{alias}}( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - Memory is **uninitialized**, which means that the contents of a returned - typed array may contain sensitive contents. - - The function supports the following data types: - - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - The default typed array data type is `float64`. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}() - [] - > arr = {{alias}}( 'float32' ) - [] - - -{{alias}}( length[, dtype] ) - Returns an uninitialized typed array having a specified length from a typed - array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > arr = {{alias}}( 5, 'int32' ) - - - -{{alias}}( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - This method shares the same security vulnerabilities mentioned above. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc() - - > arr = {{alias}}.malloc( 'float32' ) - - - -{{alias}}.malloc( length[, dtype] ) - Returns a typed array having a specified length from a typed array memory - pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc( 5 ) - - > arr = {{alias}}.malloc( 5, 'int32' ) - - - -{{alias}}.malloc( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}.malloc( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.calloc( [dtype] ) - Returns a zero-initialized typed array from a typed array memory pool. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc() - [] - > arr = {{alias}}.calloc( 'float32' ) - [] - - -{{alias}}.calloc( length[, dtype] ) - Returns a zero-initialized typed array having a specified length from a - typed array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}.calloc( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}.free( buf ) - Frees a typed array or typed array buffer for use in a future allocation. - - Parameters - ---------- - buf: TypedArray|ArrayBuffer - Typed array or typed array buffer to free. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ) - - -{{alias}}.clear() - Clears the typed array pool allowing garbage collection of previously - allocated (and currently free) array buffers. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - > {{alias}}.clear() - - -{{alias}}.highWaterMark - Read-only property returning the pool's high water mark. - - Once a high water mark is reached, typed array allocation fails. - - Examples - -------- - > {{alias}}.highWaterMark - - -{{alias}}.nbytes - Read-only property returning the total number of allocated bytes. - - The returned value is the total accumulated value. Hence, anytime a pool - must allocate a new array buffer (i.e., more memory), the pool increments - this value. - - The only time this value is decremented is when a pool is cleared. - - This behavior means that, while allocated buffers which are never freed may, - in fact, be garbage collected, they continue to count against the high water - mark limit. - - Accordingly, you should *always* free allocated buffers in order to prevent - the pool from believing that non-freed buffers are continually in use. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.nbytes - - -{{alias}}.factory( [options] ) - Creates a typed array pool. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.highWaterMark: integer (optional) - Maximum total memory (in bytes) which can be allocated. - - Returns - ------- - fcn: Function - Function for creating typed arrays from a typed array memory pool. - - Examples - -------- - > var pool = {{alias}}.factory(); - > var arr1 = pool( 3, 'float64' ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 4336c42..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,193 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-empty */ -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import typedarraypool = require( './index' ); - - -// TESTS // - -// The function returns a typed array or null... -{ - typedarraypool(); // $ExpectType TypedArrayOrNull - typedarraypool( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the function is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool( true ); // $ExpectError - typedarraypool( false ); // $ExpectError - typedarraypool( null ); // $ExpectError - typedarraypool( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized data type... -{ - typedarraypool( 4, true ); // $ExpectError - typedarraypool( 4, false ); // $ExpectError - typedarraypool( 4, null ); // $ExpectError - typedarraypool( 4, 'abc' ); // $ExpectError - typedarraypool( 4, 123 ); // $ExpectError - typedarraypool( 4, [] ); // $ExpectError - typedarraypool( 4, {} ); // $ExpectError - typedarraypool( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an incorrect number of arguments... -{ - typedarraypool( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `malloc` method which returns a typed array or null... -{ - typedarraypool.malloc(); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.malloc( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `malloc` method is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool.malloc( true ); // $ExpectError - typedarraypool.malloc( false ); // $ExpectError - typedarraypool.malloc( null ); // $ExpectError - typedarraypool.malloc( {} ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.malloc( 4, true ); // $ExpectError - typedarraypool.malloc( 4, false ); // $ExpectError - typedarraypool.malloc( 4, null ); // $ExpectError - typedarraypool.malloc( 4, 'abc' ); // $ExpectError - typedarraypool.malloc( 4, 123 ); // $ExpectError - typedarraypool.malloc( 4, [] ); // $ExpectError - typedarraypool.malloc( 4, {} ); // $ExpectError - typedarraypool.malloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided an incorrect number of arguments... -{ - typedarraypool.malloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `calloc` method which returns a typed array or null... -{ - typedarraypool.calloc(); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `calloc` method is provided a first argument which is not a number... -{ - typedarraypool.calloc( 'abc' ); // $ExpectError - typedarraypool.calloc( true ); // $ExpectError - typedarraypool.calloc( false ); // $ExpectError - typedarraypool.calloc( null ); // $ExpectError - typedarraypool.calloc( {} ); // $ExpectError - typedarraypool.calloc( [] ); // $ExpectError - typedarraypool.calloc( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.calloc( 4, true ); // $ExpectError - typedarraypool.calloc( 4, false ); // $ExpectError - typedarraypool.calloc( 4, null ); // $ExpectError - typedarraypool.calloc( 4, 'abc' ); // $ExpectError - typedarraypool.calloc( 4, 123 ); // $ExpectError - typedarraypool.calloc( 4, [] ); // $ExpectError - typedarraypool.calloc( 4, {} ); // $ExpectError - typedarraypool.calloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided an incorrect number of arguments... -{ - typedarraypool.calloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `factory` method which returns a typed array pool.. -{ - typedarraypool.factory(); // $ExpectType Pool - typedarraypool.factory( { 'highWaterMark': 556 } ); // $ExpectType Pool -} - -// The compiler throws an error if the `factory` method is provided a `highWaterMark` option which is not a number... -{ - typedarraypool.factory( { 'highWaterMark': true } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': false } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': 'abc' } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': null } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': [] } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': {} } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an incorrect number of arguments... -{ - typedarraypool.factory( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` method which returns void... -{ - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.free( arr ); // $ExpectType void -} - -// The compiler throws an error if the `free` method is provided a first argument which is neither a typed array nor array buffer... -{ - typedarraypool.free( true ); // $ExpectError - typedarraypool.free( false ); // $ExpectError - typedarraypool.free( 123 ); // $ExpectError - typedarraypool.free( 'abc' ); // $ExpectError - typedarraypool.free( null ); // $ExpectError - typedarraypool.free( {} ); // $ExpectError - typedarraypool.free( ( x: number ): number => x ); // $ExpectError -} - -// Attached to the main export is a `clear` method which returns void... -{ - typedarraypool.clear(); // $ExpectType void -} - -// The compiler throws an error if the `clear` method is provided arguments... -{ - typedarraypool.clear( {} ); // $ExpectError - typedarraypool.clear( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `highWaterMark` property... -{ - typedarraypool.highWaterMark; // $ExpectType number -} - -// Attached to the main export is a `nbytes` property... -{ - typedarraypool.nbytes; // $ExpectType number -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 24a7846..0000000 --- a/examples/index.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 randu = require( '@stdlib/random-base-randu' ); -var typedarraypool = require( './../lib' ); - -// Create a typed array pool which can allocate at most 1GB: -var typedarray = typedarraypool.factory({ - 'highWaterMark': 1e9 -}); - -// Inspect the pool: -console.log( 'Max bytes: %d', typedarray.highWaterMark ); -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Allocate an array for storing double-precision floating-point numbers: -var arr1 = typedarray( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Fill the array... -var i; -for ( i = 0; i < arr1.length; i++ ) { - arr1[ i ] = randu(); -} - -// Inspect array contents: -console.log( arr1 ); - -// Free the array: -typedarray.free( arr1 ); - -// Allocate another array similar to the previous one: -var arr2 = typedarray( 5, 'float64' ); -// returns - -// Check that we have been returned a new typed array view: -console.log( arr2 === arr1 ); -// => false - -// Inspect array contents: -console.log( arr2 ); - -// Free the array: -typedarray.free( arr2 ); - -// Allocate an initialized array: -var arr3 = typedarray.calloc( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect array contents: -console.log( arr3 ); - -// Free the array: -typedarray.free( arr3 ); - -// Clear the pool: -typedarray.clear(); - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 4254ef5..0f5442f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike, RealOrComplexTypedArray, NumericDataType as DataType } from '@stdlib/types/array'; import ArrayBuffer = require( '@stdlib/array-buffer' ); diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..822ad0a --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-setter@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/array-defaults@v0.1.0-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.1.1-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.1.0-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.1.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.1.1-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";function M(e,t){return w(t)?k(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(c("invalid option. `%s` option must be a nonnegative integer. Option: `%s`.","highWaterMark",e.highWaterMark)):null:new TypeError(c("invalid argument. Options argument must be an object. Value: `%s`.",t))}function W(e){var t,r;for(t=[],r=0;rV.highWaterMark?null:(t=new v(e),w+=e,t)}function F(e,t,r){var s;return 0===t?new e(0):null===(s=B(b(t)*E[r]))?s:new e(s,0,t)}function P(){var e,n,i,o,j,v,u,g,b;if(n=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:T,null===(i=l(n)))throw new TypeError(c("invalid argument. Must provide a recognized data type. Value: `%s`.",n));if(e<=0)return new i(0);if(r(arguments[0]))return F(i,arguments[0],n);if(s(arguments[0])){if(g=(o=arguments[0]).length,m(o)?o=h(o,0):a(o)?o=d(o,0):/^complex/.test(n)&&(g/=2),null===(j=F(i,g,n)))return j;if(z(j)||O(j))return j.set(o),j;for(u=p(o),v=f(j),b=0;b0){for(t=g(x(e.byteLength)),t=y(k.length-1,t),r=k[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = resolveGetter( arr );\n\t\t\tset = resolveSetter( out );\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","DEFAULT_DTYPE","ARRAY_DEFAULTS","get","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","resolveGetter","resolveSetter","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;q2EAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,2EAA4E,gBAAiBP,EAAKI,gBAG3H,KARC,IAAIE,UAAWC,EAAQ,qEAAsEN,GAStG,CC/BA,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,iHCcIG,EAAgBC,EAAeC,IAAK,kBACpCC,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASrB,GACjB,IAAIsB,EACAf,EACAR,EACAwB,EAGJ,GADAxB,ECjFO,CACNI,cAAiB,kBDiFbqB,UAAUC,SACdF,EAAMzB,EAAUC,EAAMC,IAErB,MAAMuB,EAaR,OAVAhB,EAAOmB,EAAYC,EAAMC,EAAM7B,EAAKI,iBACpCmB,EAAS,EAETO,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB/B,EAAKI,eAC3C+B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOb,CACP,CASD,SAASc,EAAa5B,GACrB,IAAI6B,EACA3B,EAMJ,OAHAA,EAAIkB,EAAMpB,IAGDD,EAAKkB,QAAUlB,EAAMG,GAAIe,OAC1BlB,EAAMG,GAAI4B,MAGbhB,EAAOd,EAAIT,EAAKI,cACb,MAERkC,EAAM,IAAIE,EAAa/B,GAGvBc,GAAUd,EAEH6B,EACP,CAWD,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,EACzB,CAkBD,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAtB,EACAV,EACAsC,EACAjC,EACA4B,EACAhC,EAUJ,GALCiC,GAHDG,EAAQtB,UAAUC,SACJuB,EAAUxB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGDlC,EAGK,QADd6B,EAAOzB,EAAO2B,IAEb,MAAM,IAAItC,UAAWC,EAAQ,sEAAuEqC,IAErG,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKrC,EAAsBoB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKM,EAAczB,UAAW,IAAQ,CAYrC,GAVAkB,GADAvB,EAAMK,UAAW,IACPC,OACLyB,EAAmB/B,GACvBA,EAAMgC,EAAgBhC,EAAK,GAChBiC,EAAkBjC,GAC7BA,EAAMkC,EAAelC,EAAK,GACf,WAAWmC,KAAMX,KAE5BD,GAAO,GAGK,QADbjC,EAAM+B,EAAYC,EAAMC,EAAKC,IAE5B,OAAOlC,EAER,GAAKW,EAAiBX,IAASS,EAAgBT,GAE9C,OADAA,EAAIsC,IAAK5B,GACFV,EAKR,IAFAK,EAAMyC,EAAepC,GACrB4B,EAAMS,EAAe/C,GACfC,EAAI,EAAGA,EAAIgC,EAAKhC,IACrBqC,EAAKtC,EAAKC,EAAGI,EAAKK,EAAKT,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,wGAAyGkB,UAAW,IACjJ,CAgBD,SAASO,IACR,IAAIe,EACArC,EACAgD,EACA/C,EAUJ,GAAa,QANZD,EADc,KADfqC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCiC,EADIrC,EAAiBX,GACf0C,EAAgB1C,EAAK,GAChBS,EAAgBT,GACrB4C,EAAe5C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAI+C,EAAIhC,OAAQf,IAC5B+C,EAAK/C,GAAM,EAGb,OAAOD,CACP,CAcD,SAASuB,EAAMK,GACd,IAAI7B,EACAkD,EACAhD,EACJ,GAAKiD,EAAkBtB,IAASA,EAAIuB,OACnCvB,EAAMA,EAAIuB,YACJ,IAAMC,EAAexB,GAC3B,MAAM,IAAIhC,UAAWC,EAAQ,4EAA6E+B,IAE3G,GAAKA,EAAIyB,WAAa,EAAI,CAQzB,IAPAtD,EAAIuD,EAAOnC,EAAMS,EAAIyB,aAGrBtD,EAAIwD,EAAKzD,EAAKkB,OAAO,EAAGjB,GAGxBkD,EAAInD,EAAMC,GACJE,EAAI,EAAGA,EAAIgD,EAAEjC,OAAQf,IAC1B,GAAKgD,EAAGhD,KAAQ2B,EACf,OAAO,EAITqB,EAAE/C,KAAM0B,EACR,CACD,OAAO,CACP,CAOD,SAASJ,IACR,IAAIvB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKkB,OAAQf,IAC7BH,EAAMG,GAAIe,OAAS,EAEpBH,EAAS,CACT,CACF,CErTG,IAAC2C,EAAiB5C,ICPrBQ,EAAAqC,EAAA,UAAA7C"} \ No newline at end of file diff --git a/lib/bytes_per_element.json b/lib/bytes_per_element.json deleted file mode 100644 index f97fe70..0000000 --- a/lib/bytes_per_element.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "float64": 8, - "float32": 4, - "int16": 2, - "int32": 4, - "int8": 1, - "uint16": 2, - "uint32": 4, - "uint8": 1, - "uint8c": 1, - "complex64": 8, - "complex128": 16 -} diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index a421711..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +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'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'highWaterMark': 9007199254740992 - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 4365791..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,372 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var isComplex64Array = require( '@stdlib/assert-is-complex64array' ); -var isComplex128Array = require( '@stdlib/assert-is-complex128array' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var ctors = require( '@stdlib/array-typed-ctors' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var resolveSetter = require( '@stdlib/array-base-resolve-setter' ); -var ARRAY_DEFAULTS = require( '@stdlib/array-defaults' ); -var format = require( '@stdlib/string-format' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil = require( '@stdlib/math-base-special-ceil' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); -var log2 = require( '@stdlib/math-base-special-log2' ); -var min = require( '@stdlib/math-base-special-min' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var createPool = require( './pool.js' ); -var BYTES_PER_ELEMENT = require( './bytes_per_element.json' ); - - -// VARIABLES // - -var DEFAULT_DTYPE = ARRAY_DEFAULTS.get( 'dtypes.default' ); -var Complex64Array = ctors( 'complex64' ); -var Complex128Array = ctors( 'complex128' ); - - -// FUNCTIONS // - -/** -* Tests whether an array is a single-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a single-precision complex floating-point number array -*/ -function isCmplx64Array( arr ) { - return ( arr instanceof Complex64Array ); -} - -/** -* Tests whether an array is a double-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a double-precision complex floating-point number array -*/ -function isCmplx128Array( arr ) { - return ( arr instanceof Complex128Array ); -} - - -// MAIN // - -/** -* Creates a typed array pool. -* -* @param {Options} [options] - pool options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} allocator -* -* @example -* var typedarraypool = factory(); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -function factory( options ) { - var nbytes; - var pool; - var opts; - var err; - - opts = defaults(); - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - pool = createPool( ceil( log2( opts.highWaterMark ) ) ); - nbytes = 0; - - setReadOnly( malloc, 'malloc', malloc ); // circular reference - setReadOnly( malloc, 'calloc', calloc ); - setReadOnly( malloc, 'free', free ); - setReadOnly( malloc, 'clear', clear ); - setReadOnly( malloc, 'highWaterMark', opts.highWaterMark ); - setReadOnlyAccessor( malloc, 'nbytes', getBytes ); - - return malloc; - - /** - * Returns the number of allocated bytes. - * - * @private - * @returns {NonNegativeInteger} number of allocated bytes - */ - function getBytes() { - return nbytes; - } - - /** - * Returns an array buffer. - * - * @private - * @param {NonNegativeInteger} n - number of bytes - * @returns {(ArrayBuffer|null)} array buffer or null - */ - function arraybuffer( n ) { - var buf; - var i; - - // Convert the number of bytes to an index in our pool table: - i = log2( n ); - - // If we already have an available array buffer, use it... - if ( i < pool.length && pool[ i ].length ) { - return pool[ i ].pop(); - } - // Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate... - if ( nbytes+n > opts.highWaterMark ) { - return null; - } - buf = new ArrayBuffer( n ); - - // Update the running counter of allocated bytes: - nbytes += n; - - return buf; - } - - /** - * Returns a typed array. - * - * @private - * @param {Function} ctor - typed array constructor - * @param {NonNegativeInteger} len - view length - * @param {string} dtype - data type - * @returns {(TypedArray|null)} typed array or null - */ - function typedarray( ctor, len, dtype ) { - var buf; - if ( len === 0 ) { - return new ctor( 0 ); - } - buf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] ); - if ( buf === null ) { - return buf; - } - return new ctor( buf, 0, len ); - } - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length or an array-like object - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function malloc() { - var nargs; - var dtype; - var ctor; - var arr; - var out; - var set; - var get; - var len; - var i; - - nargs = arguments.length; - if ( nargs && isString( arguments[ nargs-1 ] ) ) { - nargs -= 1; - dtype = arguments[ nargs ]; - } else { - dtype = DEFAULT_DTYPE; - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) ); - } - if ( nargs <= 0 ) { - return new ctor( 0 ); - } - // Check if provided a typed array length... - if ( isNonNegativeInteger( arguments[ 0 ] ) ) { - return typedarray( ctor, arguments[ 0 ], dtype ); - } - // Check if provided an array-like object containing data elements... - if ( isCollection( arguments[ 0 ] ) ) { - arr = arguments[ 0 ]; - len = arr.length; - if ( isComplex128Array( arr ) ) { - arr = reinterpret128( arr, 0 ); - } else if ( isComplex64Array( arr ) ) { - arr = reinterpret64( arr, 0 ); - } else if ( /^complex/.test( dtype ) ) { - // Assume we've been provided an array of interleaved real and imaginary components... - len /= 2; - } - out = typedarray( ctor, len, dtype ); - if ( out === null ) { - return out; - } - if ( isCmplx128Array( out ) || isCmplx64Array( out ) ) { - out.set( arr ); - return out; - } - // Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other "unsafe" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things... - get = resolveGetter( arr ); - set = resolveSetter( out ); - for ( i = 0; i < len; i++ ) { - set( out, i, get( arr, i ) ); - } - return out; - } - throw new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) ); - } - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {NonNegativeInteger} [len=0] - array length - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function calloc() { - var nargs; - var out; - var tmp; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - out = malloc(); - } else if ( nargs === 1 ) { - out = malloc( arguments[ 0 ] ); - } else { - out = malloc( arguments[ 0 ], arguments[ 1 ] ); - } - if ( out !== null ) { - // Initialize the memory... - if ( isCmplx128Array( out ) ) { - tmp = reinterpret128( out, 0 ); - } else if ( isCmplx64Array( out ) ) { - tmp = reinterpret64( out, 0 ); - } else { - tmp = out; - } - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = 0.0; - } - } - return out; - } - - /** - * Frees a typed array or typed array buffer. - * - * ## Notes - * - * - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., "freeing" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool. - * - * @private - * @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free - * @throws {TypeError} must provide a typed array or typed array buffer - * @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed - */ - function free( buf ) { - var n; - var p; - var i; - if ( isTypedArrayLike( buf ) && buf.buffer ) { - buf = buf.buffer; - } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) ); - } - if ( buf.byteLength > 0 ) { - n = floor( log2( buf.byteLength ) ); - - // Prohibit "freeing" array buffers which would potentially allow users to circumvent high water mark limits: - n = min( pool.length-1, n ); - - // Ensure that we do not attempt to free the same buffer more than once... - p = pool[ n ]; - for ( i = 0; i < p.length; i++ ) { - if ( p[ i ] === buf ) { - return false; - } - } - // Add the buffer to our pool of free buffers: - p.push( buf ); - } - return true; - } - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @private - */ - function clear() { - var i; - for ( i = 0; i < pool.length; i++ ) { - pool[ i ].length = 0; - } - nbytes = 0; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6c12a4e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Typed array pool. -* -* @module @stdlib/array-pool -* -* @example -* var typedarraypool = require( '@stdlib/array-pool' ); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8f69ee3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,63 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @name typedarraypool -* @type {Function} -* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a valid array length or an array-like object -* @throws {TypeError} must provide a recognized data type -* @returns {(TypedArray|null)} typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -var typedarraypool = factory(); - - -// EXPORTS // - -module.exports = typedarraypool; diff --git a/lib/pool.js b/lib/pool.js deleted file mode 100644 index 5abd287..0000000 --- a/lib/pool.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Initializes a cache for pooled typed array buffers. -* -* @private -* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size -* @returns {ArrayArray} initialized cache -*/ -function pool( n ) { - var out; - var i; - - out = []; - for ( i = 0; i < n+1; i++ ) { - out.push( [] ); - } - return out; -} - - -// EXPORTS // - -module.exports = pool; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index ce54890..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'highWaterMark': 1024 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'highWaterMark' ) ) { - opts.highWaterMark = options.highWaterMark; - if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 5de5f4f..bd7b179 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Typed array pool.", "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,77 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-resolve-getter": "^0.1.0", - "@stdlib/array-base-resolve-setter": "github:stdlib-js/array-base-resolve-setter#main", - "@stdlib/array-buffer": "^0.1.0", - "@stdlib/array-defaults": "^0.1.0", - "@stdlib/array-typed-ctors": "^0.1.0", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-arraybuffer": "^0.1.1", - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-complex128array": "^0.1.0", - "@stdlib/assert-is-complex64array": "^0.1.0", - "@stdlib/assert-is-nonnegative-integer": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/assert-is-string": "^0.1.1", - "@stdlib/assert-is-typed-array-like": "^0.1.0", - "@stdlib/math-base-special-ceil": "^0.1.1", - "@stdlib/math-base-special-ceil2": "^0.1.0", - "@stdlib/math-base-special-floor": "^0.1.1", - "@stdlib/math-base-special-log2": "^0.1.1", - "@stdlib/math-base-special-min": "^0.1.1", - "@stdlib/strided-base-reinterpret-complex128": "^0.1.1", - "@stdlib/strided-base-reinterpret-complex64": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.3.1", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.1.1", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.1" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.1.0", - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-float32": "^0.1.1", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/array-int16": "^0.1.1", - "@stdlib/array-int32": "^0.1.1", - "@stdlib/array-int8": "^0.1.1", - "@stdlib/array-uint16": "^0.1.1", - "@stdlib/array-uint32": "^0.1.1", - "@stdlib/array-uint8": "^0.1.1", - "@stdlib/array-uint8c": "^0.1.1", - "@stdlib/assert-instance-of": "^0.1.1", - "@stdlib/assert-is-complex-typed-array": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-typed-array": "^0.1.0", - "@stdlib/complex-float32": "^0.1.1", - "@stdlib/complex-float64": "^0.1.1", - "@stdlib/complex-imag": "^0.1.1", - "@stdlib/complex-imagf": "^0.1.1", - "@stdlib/complex-real": "^0.1.1", - "@stdlib/complex-realf": "^0.1.1", - "@stdlib/math-base-special-pow": "^0.1.0", - "@stdlib/random-base-randu": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..988bba3 --- /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.factory.js b/test/test.factory.js deleted file mode 100644 index 396aee2..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,2240 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function (no options)', function test( t ) { - t.strictEqual( typeof factory(), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - t.strictEqual( typeof factory( {} ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided a `highWaterMark` option which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (length)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a function which returns a typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, length)', function test( t ) { - var typedarraypool = factory(); - var arr; - - arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a `malloc` method which is a circular reference', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - var buf; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the returned function is a property which returns the pool\'s high water mark', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function supports specifying a high water mark which limits the total amount of memory a pool can allocate', function test( t ) { - var typedarraypool; - var arr1; - var arr2; - - typedarraypool = factory({ - 'highWaterMark': 64 // bytes - }); - - typedarraypool.clear(); - - arr1 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr1.length, 8, 'returns expected value' ); - t.strictEqual( arr1.byteLength, 64, 'returns expected value' ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - typedarraypool.free( arr1 ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Create an array which is less than or equal to the high water mark: - arr2 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr2.length, 8, 'returns expected value' ); - t.strictEqual( arr2.byteLength, 64, 'returns expected value' ); - - typedarraypool.free( arr2 ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a property which returns the total number of accumulated bytes', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var typedarraypool; - var arrs; - var i; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 54aa5ee..0000000 --- a/test/test.js +++ /dev/null @@ -1,1797 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var typedarraypool = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -}); From 58b3862d94cdd949813d4f2f9378a51abbab5ad3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 00:59:53 +0000 Subject: [PATCH 067/103] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a32af6a..7fa2632 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "@stdlib/math-base-special-min": "^0.2.0", "@stdlib/strided-base-reinterpret-complex128": "^0.2.0", "@stdlib/strided-base-reinterpret-complex64": "^0.2.0", - "@stdlib/string-format": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.0", "@stdlib/types": "^0.3.1", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.0" From 35afda8435a9ef2eb9afa40e6f644c07326ca54b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:27:30 +0000 Subject: [PATCH 068/103] Remove files --- index.d.ts | 359 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6541 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 0f5442f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,359 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike, RealOrComplexTypedArray, NumericDataType as DataType } from '@stdlib/types/array'; -import ArrayBuffer = require( '@stdlib/array-buffer' ); - -/** -* Typed array or null. -*/ -type TypedArrayOrNull = RealOrComplexTypedArray | null; - -/** -* Interface defining pool options. -*/ -interface Options { - /** - * Maximum total memory which can be allocated. - */ - highWaterMark?: number; -} - -/** -* Pool interface. -*/ -interface Pool { - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr = typedarraypool(); - * // returns [] - * - * @example - * var arr = typedarraypool( 'float32' ); - * // returns [] - */ - ( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * // Allocate an array of doubles: - * var arr = typedarraypool( 5, 'float64' ); - * // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * typedarraypool.free( arr ); - * - * @example - * var arr1 = typedarraypool( [ 0.5, 0.5, 0.5 ] ); - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * @example - * var arr1 = [ 0.5, 0.5, 0.5 ]; - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - */ - ( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc(); - * // returns [] - * - * var arr2 = typedarraypool.calloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param length - typed array length - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc( 5 ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * var arr2 = typedarraypool.calloc( 5, 'uint8' ); - * // returns [ 0, 0, 0, 0, 0 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( length: number, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc(); - * // returns [] - * - * var arr2 = typedarraypool.malloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc( 5 ); - * // returns - * - * var arr2 = typedarraypool.malloc( 5, 'uint8' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 5.0, -3.0, 2.0 ] ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr2 = typedarraypool.malloc( arr1 ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr3 = typedarraypool.malloc( arr1, 'int32' ); - * // returns [ 5, -3, 2 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * typedarraypool.free( arr3 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ] ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * var arr2 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ], 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Frees a typed array or typed array buffer for use in a future allocation. - * - * @param buf - typed array or typed array buffer to free - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array for use in a future allocation: - * typedarraypool.free( arr ); - * - * // Create another typed array: - * arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array buffer for use in a future allocation: - * typedarraypool.free( arr.buffer ); - */ - free( buf: RealOrComplexTypedArray | ArrayBuffer ): void; - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr ); - * - * // ... - * - * // Clear all freed buffers: - * typedarraypool.clear(); - */ - clear(): void; - - /** - * Read-only property returning the pool's high water mark. - * - * ## Notes - * - * - Once a high water mark is reached, typed array allocation fails. - * - * @example - * var limit = typedarraypool.highWaterMark; - * // returns - */ - readonly highWaterMark: number; - - /** - * Read-only property returning the total number of allocated bytes. - * - * @example - * var arr = typedarraypool( 5, 'float64' ); - * - * var nbytes = typedarraypool.nbytes; - * // returns - */ - readonly nbytes: number; - - /** - * Creates a typed array pool. - * - * @param options - pool options - * @param options.highWaterMark - maximum total memory which can be allocated - * @throws must provide valid options - * @returns allocator - * - * @example - * var allocator = typedarraypool.factory(); - * - * // Allocate an array of doubles: - * var arr = allocator( 5, 'float64' ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * allocator.free( arr ); - */ - factory( options?: Options ): Pool; -} - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @param arg - an array length or an array-like object -* @param dtype - data type (default: 'float64') -* @returns typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -declare var typedarraypool: Pool; - - -// EXPORTS // - -export = typedarraypool; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 822ad0a..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.1.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.1.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.1.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-setter@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/array-defaults@v0.1.0-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.1.0-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.1.1-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.1.0-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.1.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.1.1-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";function M(e,t){return w(t)?k(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(c("invalid option. `%s` option must be a nonnegative integer. Option: `%s`.","highWaterMark",e.highWaterMark)):null:new TypeError(c("invalid argument. Options argument must be an object. Value: `%s`.",t))}function W(e){var t,r;for(t=[],r=0;rV.highWaterMark?null:(t=new v(e),w+=e,t)}function F(e,t,r){var s;return 0===t?new e(0):null===(s=B(b(t)*E[r]))?s:new e(s,0,t)}function P(){var e,n,i,o,j,v,u,g,b;if(n=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:T,null===(i=l(n)))throw new TypeError(c("invalid argument. Must provide a recognized data type. Value: `%s`.",n));if(e<=0)return new i(0);if(r(arguments[0]))return F(i,arguments[0],n);if(s(arguments[0])){if(g=(o=arguments[0]).length,m(o)?o=h(o,0):a(o)?o=d(o,0):/^complex/.test(n)&&(g/=2),null===(j=F(i,g,n)))return j;if(z(j)||O(j))return j.set(o),j;for(u=p(o),v=f(j),b=0;b0){for(t=g(x(e.byteLength)),t=y(k.length-1,t),r=k[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = resolveGetter( arr );\n\t\t\tset = resolveSetter( out );\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","DEFAULT_DTYPE","ARRAY_DEFAULTS","get","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","resolveGetter","resolveSetter","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;q2EAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,2EAA4E,gBAAiBP,EAAKI,gBAG3H,KARC,IAAIE,UAAWC,EAAQ,qEAAsEN,GAStG,CC/BA,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,iHCcIG,EAAgBC,EAAeC,IAAK,kBACpCC,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASrB,GACjB,IAAIsB,EACAf,EACAR,EACAwB,EAGJ,GADAxB,ECjFO,CACNI,cAAiB,kBDiFbqB,UAAUC,SACdF,EAAMzB,EAAUC,EAAMC,IAErB,MAAMuB,EAaR,OAVAhB,EAAOmB,EAAYC,EAAMC,EAAM7B,EAAKI,iBACpCmB,EAAS,EAETO,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB/B,EAAKI,eAC3C+B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOb,CACP,CASD,SAASc,EAAa5B,GACrB,IAAI6B,EACA3B,EAMJ,OAHAA,EAAIkB,EAAMpB,IAGDD,EAAKkB,QAAUlB,EAAMG,GAAIe,OAC1BlB,EAAMG,GAAI4B,MAGbhB,EAAOd,EAAIT,EAAKI,cACb,MAERkC,EAAM,IAAIE,EAAa/B,GAGvBc,GAAUd,EAEH6B,EACP,CAWD,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,EACzB,CAkBD,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAtB,EACAV,EACAsC,EACAjC,EACA4B,EACAhC,EAUJ,GALCiC,GAHDG,EAAQtB,UAAUC,SACJuB,EAAUxB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGDlC,EAGK,QADd6B,EAAOzB,EAAO2B,IAEb,MAAM,IAAItC,UAAWC,EAAQ,sEAAuEqC,IAErG,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKrC,EAAsBoB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKM,EAAczB,UAAW,IAAQ,CAYrC,GAVAkB,GADAvB,EAAMK,UAAW,IACPC,OACLyB,EAAmB/B,GACvBA,EAAMgC,EAAgBhC,EAAK,GAChBiC,EAAkBjC,GAC7BA,EAAMkC,EAAelC,EAAK,GACf,WAAWmC,KAAMX,KAE5BD,GAAO,GAGK,QADbjC,EAAM+B,EAAYC,EAAMC,EAAKC,IAE5B,OAAOlC,EAER,GAAKW,EAAiBX,IAASS,EAAgBT,GAE9C,OADAA,EAAIsC,IAAK5B,GACFV,EAKR,IAFAK,EAAMyC,EAAepC,GACrB4B,EAAMS,EAAe/C,GACfC,EAAI,EAAGA,EAAIgC,EAAKhC,IACrBqC,EAAKtC,EAAKC,EAAGI,EAAKK,EAAKT,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,wGAAyGkB,UAAW,IACjJ,CAgBD,SAASO,IACR,IAAIe,EACArC,EACAgD,EACA/C,EAUJ,GAAa,QANZD,EADc,KADfqC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCiC,EADIrC,EAAiBX,GACf0C,EAAgB1C,EAAK,GAChBS,EAAgBT,GACrB4C,EAAe5C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAI+C,EAAIhC,OAAQf,IAC5B+C,EAAK/C,GAAM,EAGb,OAAOD,CACP,CAcD,SAASuB,EAAMK,GACd,IAAI7B,EACAkD,EACAhD,EACJ,GAAKiD,EAAkBtB,IAASA,EAAIuB,OACnCvB,EAAMA,EAAIuB,YACJ,IAAMC,EAAexB,GAC3B,MAAM,IAAIhC,UAAWC,EAAQ,4EAA6E+B,IAE3G,GAAKA,EAAIyB,WAAa,EAAI,CAQzB,IAPAtD,EAAIuD,EAAOnC,EAAMS,EAAIyB,aAGrBtD,EAAIwD,EAAKzD,EAAKkB,OAAO,EAAGjB,GAGxBkD,EAAInD,EAAMC,GACJE,EAAI,EAAGA,EAAIgD,EAAEjC,OAAQf,IAC1B,GAAKgD,EAAGhD,KAAQ2B,EACf,OAAO,EAITqB,EAAE/C,KAAM0B,EACR,CACD,OAAO,CACP,CAOD,SAASJ,IACR,IAAIvB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKkB,OAAQf,IAC7BH,EAAMG,GAAIe,OAAS,EAEpBH,EAAS,CACT,CACF,CErTG,IAAC2C,EAAiB5C,ICPrBQ,EAAAqC,EAAA,UAAA7C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 988bba3..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 365efb39c1900e2ccb36ba551a9dd5b2e9e515d1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:28:54 +0000 Subject: [PATCH 069/103] 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 | 45 +- SECURITY.md | 5 - benchmark/benchmark.calloc.js | 246 - benchmark/benchmark.factory.js | 71 - benchmark/benchmark.js | 246 - benchmark/benchmark.length.complex128.js | 102 - benchmark/benchmark.length.complex64.js | 102 - benchmark/benchmark.length.float32.js | 102 - benchmark/benchmark.length.float64.js | 102 - benchmark/benchmark.length.int16.js | 102 - benchmark/benchmark.length.int32.js | 102 - benchmark/benchmark.length.int8.js | 102 - benchmark/benchmark.length.uint16.js | 102 - benchmark/benchmark.length.uint32.js | 102 - benchmark/benchmark.length.uint8.js | 102 - benchmark/benchmark.length.uint8c.js | 102 - benchmark/benchmark.malloc.js | 246 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 347 -- docs/types/test.ts | 193 - examples/index.js | 80 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/bytes_per_element.json | 13 - lib/defaults.js | 42 - lib/factory.js | 372 -- lib/index.js | 56 - lib/main.js | 63 - lib/pool.js | 44 - lib/validate.js | 66 - package.json | 98 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 2240 -------- test/test.js | 1797 ------ 62 files changed, 6206 insertions(+), 10650 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.calloc.js delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.complex128.js delete mode 100644 benchmark/benchmark.length.complex64.js delete mode 100644 benchmark/benchmark.length.float32.js delete mode 100644 benchmark/benchmark.length.float64.js delete mode 100644 benchmark/benchmark.length.int16.js delete mode 100644 benchmark/benchmark.length.int32.js delete mode 100644 benchmark/benchmark.length.int8.js delete mode 100644 benchmark/benchmark.length.uint16.js delete mode 100644 benchmark/benchmark.length.uint32.js delete mode 100644 benchmark/benchmark.length.uint8.js delete mode 100644 benchmark/benchmark.length.uint8c.js delete mode 100644 benchmark/benchmark.malloc.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/bytes_per_element.json delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/pool.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ea35f20..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/array/pool) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6f7c875..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/array/pool) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 beada65..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -495,7 +492,7 @@ console.log( 'nbytes: %d', typedarray.nbytes ); ## 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]. @@ -564,7 +561,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/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.calloc.js b/benchmark/benchmark.calloc.js deleted file mode 100644 index fd8f53d..0000000 --- a/benchmark/benchmark.calloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':calloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 58918bb..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = typedarray.factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:highWaterMark', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'highWaterMark': 0 - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.highWaterMark = i; - f = typedarray.factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 4310559..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.complex128.js b/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 12c6668..0000000 --- a/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex64.js b/benchmark/benchmark.length.complex64.js deleted file mode 100644 index ca2b45c..0000000 --- a/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float32.js b/benchmark/benchmark.length.float32.js deleted file mode 100644 index b3b4508..0000000 --- a/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float64.js b/benchmark/benchmark.length.float64.js deleted file mode 100644 index 5f0132d..0000000 --- a/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int16.js b/benchmark/benchmark.length.int16.js deleted file mode 100644 index 9f253cb..0000000 --- a/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int32.js b/benchmark/benchmark.length.int32.js deleted file mode 100644 index f83e795..0000000 --- a/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int8.js b/benchmark/benchmark.length.int8.js deleted file mode 100644 index 5b01174..0000000 --- a/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint16.js b/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 32b0a5d..0000000 --- a/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint32.js b/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 290b90c..0000000 --- a/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8.js b/benchmark/benchmark.length.uint8.js deleted file mode 100644 index ff7d733..0000000 --- a/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8c.js b/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index 8f0d10a..0000000 --- a/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.malloc.js b/benchmark/benchmark.malloc.js deleted file mode 100644 index 1661907..0000000 --- a/benchmark/benchmark.malloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':malloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 612de17..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/array/pool" -%% click B href "https://github.com/stdlib-js/array-pool/tree/main" -%% click C href "https://github.com/stdlib-js/array-pool/tree/production" -%% click D href "https://github.com/stdlib-js/array-pool/tree/esm" -%% click E href "https://github.com/stdlib-js/array-pool/tree/deno" -%% click F href "https://github.com/stdlib-js/array-pool/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/pool -[production-url]: https://github.com/stdlib-js/array-pool/tree/production -[deno-url]: https://github.com/stdlib-js/array-pool/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-pool/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-pool/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-pool/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-pool/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-pool/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 5160b6f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import typedarraypool from '../docs/types/index'; -export = typedarraypool; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4f5b474..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var l=function(n,i){return function(){return i||n((i={exports:{}}).exports,i),i.exports}};var M=l(function(Er,w){ -function I(){return{highWaterMark:9007199254740992}}w.exports=I -});var T=l(function(Tr,E){ -var U=require('@stdlib/assert-is-plain-object/dist'),z=require('@stdlib/assert-has-own-property/dist'),G=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,k=require('@stdlib/error-tools-fmtprodmsg/dist');function H(n,i){return U(i)?z(i,"highWaterMark")&&(n.highWaterMark=i.highWaterMark,!G(n.highWaterMark))?new TypeError(k('01H2t',"highWaterMark",n.highWaterMark)):null:new TypeError(k('01H2V',i));}E.exports=H -});var C=l(function(Wr,W){ -function J(n){var i,u;for(i=[],u=0;uv.highWaterMark?null:(e=new or(r),i+=r,e)}function d(r,e,a){var t;return e===0?new r(0):(t=j(vr(e)*mr[a]),t===null?t:new r(t,0,e))}function o(){var r,e,a,t,s,x,A,c,f;if(r=arguments.length,r&&Q(arguments[r-1])?(r-=1,e=arguments[r]):e=pr,a=y(e),a===null)throw new TypeError(m('01H2Y',e));if(r<=0)return new a(0);if(X(arguments[0]))return d(a,arguments[0],e);if(Z(arguments[0])){if(t=arguments[0],c=t.length,tr(t)?t=b(t,0):er(t)?t=P(t,0):/^complex/.test(e)&&(c/=2),s=d(a,c,e),s===null)return s;if(R(s)||L(s))return s.set(t),s;for(A=ir(t),x=nr(s),f=0;f0){for(e=lr(p(r.byteLength)),e=fr(u.length-1,e),a=u[e],t=0;t[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = resolveGetter( arr );\n\t\t\tset = resolveSetter( out );\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nmodule.exports = typedarraypool;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* var typedarraypool = require( '@stdlib/array-pool' );\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,cAAiB,gBAClB,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,eAAgB,IACzCD,EAAK,cAAgBC,EAAQ,cACxB,CAACJ,EAAsBG,EAAK,aAAc,GACvC,IAAI,UAAWF,EAAQ,2EAA4E,gBAAiBE,EAAK,aAAc,CAAE,EAG3I,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cA6BA,SAASC,EAAM,EAAI,CAClB,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAI,EAAE,EAAGA,IACrBD,EAAI,KAAM,CAAC,CAAE,EAEd,OAAOA,CACR,CAKAF,EAAO,QAAUC,IC3CjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,QAAW,EACX,QAAW,EACX,MAAS,EACT,MAAS,EACT,KAAQ,EACR,OAAU,EACV,OAAU,EACV,MAAS,EACT,OAAU,EACT,UAAa,EACb,WAAc,EAChB,ICZA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAe,QAAS,8BAA+B,EACvDC,EAAmB,QAAS,oCAAqC,EACjEC,GAAgB,QAAS,+BAAgC,EACzDC,GAAmB,QAAS,kCAAmC,EAC/DC,GAAoB,QAAS,mCAAoC,EACjEC,EAAc,QAAS,uDAAwD,EAC/EC,GAAsB,QAAS,uDAAwD,EACvFC,EAAQ,QAAS,2BAA4B,EAC7CC,EAAgB,QAAS,4CAA6C,EACtEC,EAAiB,QAAS,6CAA8C,EACxEC,GAAgB,QAAS,mCAAoC,EAC7DC,GAAgB,QAAS,mCAAoC,EAC7DC,GAAiB,QAAS,wBAAyB,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,GAAc,QAAS,sBAAuB,EAC9CC,GAAO,QAAS,gCAAiC,EACjDC,GAAQ,QAAS,iCAAkC,EACnDC,GAAQ,QAAS,iCAAkC,EACnDC,EAAO,QAAS,gCAAiC,EACjDC,GAAM,QAAS,+BAAgC,EAC/CC,GAAW,IACXC,GAAW,IACXC,GAAa,IACbC,GAAoB,IAKpBC,GAAgBZ,GAAe,IAAK,gBAAiB,EACrDa,GAAiBlB,EAAO,WAAY,EACpCmB,GAAkBnB,EAAO,YAAa,EAY1C,SAASoB,EAAgBC,EAAM,CAC9B,OAASA,aAAeH,EACzB,CASA,SAASI,EAAiBD,EAAM,CAC/B,OAASA,aAAeF,EACzB,CA6BA,SAASI,GAASC,EAAU,CAC3B,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,EAAOd,GAAS,EACX,UAAU,SACde,EAAMd,GAAUa,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAAF,EAAOX,GAAYP,GAAMG,EAAMgB,EAAK,aAAc,CAAE,CAAE,EACtDF,EAAS,EAET3B,EAAa+B,EAAQ,SAAUA,CAAO,EACtC/B,EAAa+B,EAAQ,SAAUC,CAAO,EACtChC,EAAa+B,EAAQ,OAAQE,CAAK,EAClCjC,EAAa+B,EAAQ,QAASG,CAAM,EACpClC,EAAa+B,EAAQ,gBAAiBF,EAAK,aAAc,EACzD5B,GAAqB8B,EAAQ,SAAUI,CAAS,EAEzCJ,EAQP,SAASI,GAAW,CACnB,OAAOR,CACR,CASA,SAASS,EAAaC,EAAI,CACzB,IAAIC,EACAC,EAMJ,OAHAA,EAAI1B,EAAMwB,CAAE,EAGPE,EAAIX,EAAK,QAAUA,EAAMW,CAAE,EAAE,OAC1BX,EAAMW,CAAE,EAAE,IAAI,EAGjBZ,EAAOU,EAAIR,EAAK,cACb,MAERS,EAAM,IAAI7B,GAAa4B,CAAE,EAGzBV,GAAUU,EAEHC,EACR,CAWA,SAASE,EAAYC,EAAMC,EAAKC,EAAQ,CACvC,IAAIL,EACJ,OAAKI,IAAQ,EACL,IAAID,EAAM,CAAE,GAEpBH,EAAMF,EAAaxB,GAAO8B,CAAI,EAAExB,GAAmByB,CAAM,CAAE,EACtDL,IAAQ,KACLA,EAED,IAAIG,EAAMH,EAAK,EAAGI,CAAI,EAC9B,CAkBA,SAASX,GAAS,CACjB,IAAIa,EACAD,EACAF,EACAlB,EACAsB,EACAC,EACAC,EACAL,EACAH,EAUJ,GARAK,EAAQ,UAAU,OACbA,GAASnD,EAAU,UAAWmD,EAAM,CAAE,CAAE,GAC5CA,GAAS,EACTD,EAAQ,UAAWC,CAAM,GAEzBD,EAAQxB,GAETsB,EAAOvC,EAAOyC,CAAM,EACfF,IAAS,KACb,MAAM,IAAI,UAAWjC,EAAQ,sEAAuEmC,CAAM,CAAE,EAE7G,GAAKC,GAAS,EACb,OAAO,IAAIH,EAAM,CAAE,EAGpB,GAAK/C,EAAsB,UAAW,CAAE,CAAE,EACzC,OAAO8C,EAAYC,EAAM,UAAW,CAAE,EAAGE,CAAM,EAGhD,GAAKhD,EAAc,UAAW,CAAE,CAAE,EAAI,CAYrC,GAXA4B,EAAM,UAAW,CAAE,EACnBmB,EAAMnB,EAAI,OACLxB,GAAmBwB,CAAI,EAC3BA,EAAMnB,EAAgBmB,EAAK,CAAE,EAClBzB,GAAkByB,CAAI,EACjCA,EAAMpB,EAAeoB,EAAK,CAAE,EACjB,WAAW,KAAMoB,CAAM,IAElCD,GAAO,GAERG,EAAML,EAAYC,EAAMC,EAAKC,CAAM,EAC9BE,IAAQ,KACZ,OAAOA,EAER,GAAKrB,EAAiBqB,CAAI,GAAKvB,EAAgBuB,CAAI,EAClD,OAAAA,EAAI,IAAKtB,CAAI,EACNsB,EAKR,IAFAE,EAAM1C,GAAekB,CAAI,EACzBuB,EAAMxC,GAAeuC,CAAI,EACnBN,EAAI,EAAGA,EAAIG,EAAKH,IACrBO,EAAKD,EAAKN,EAAGQ,EAAKxB,EAAKgB,CAAE,CAAE,EAE5B,OAAOM,CACR,CACA,MAAM,IAAI,UAAWrC,EAAQ,wGAAyG,UAAW,CAAE,CAAE,CAAE,CACxJ,CAgBA,SAASwB,GAAS,CACjB,IAAIY,EACAC,EACAG,EACAT,EAUJ,GARAK,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAMd,EAAO,EACFa,IAAU,EACrBC,EAAMd,EAAQ,UAAW,CAAE,CAAE,EAE7Bc,EAAMd,EAAQ,UAAW,CAAE,EAAG,UAAW,CAAE,CAAE,EAEzCc,IAAQ,KASZ,IAPKrB,EAAiBqB,CAAI,EACzBG,EAAM5C,EAAgByC,EAAK,CAAE,EAClBvB,EAAgBuB,CAAI,EAC/BG,EAAM7C,EAAe0C,EAAK,CAAE,EAE5BG,EAAMH,EAEDN,EAAI,EAAGA,EAAIS,EAAI,OAAQT,IAC5BS,EAAKT,CAAE,EAAI,EAGb,OAAOM,CACR,CAcA,SAASZ,EAAMK,EAAM,CACpB,IAAID,EACAY,EACAV,EACJ,GAAK3C,EAAkB0C,CAAI,GAAKA,EAAI,OACnCA,EAAMA,EAAI,eACC,CAACzC,GAAeyC,CAAI,EAC/B,MAAM,IAAI,UAAW9B,EAAQ,4EAA6E8B,CAAI,CAAE,EAEjH,GAAKA,EAAI,WAAa,EAAI,CAQzB,IAPAD,EAAI1B,GAAOE,EAAMyB,EAAI,UAAW,CAAE,EAGlCD,EAAIvB,GAAKc,EAAK,OAAO,EAAGS,CAAE,EAG1BY,EAAIrB,EAAMS,CAAE,EACNE,EAAI,EAAGA,EAAIU,EAAE,OAAQV,IAC1B,GAAKU,EAAGV,CAAE,IAAMD,EACf,MAAO,GAITW,EAAE,KAAMX,CAAI,CACb,CACA,MAAO,EACR,CAOA,SAASJ,GAAQ,CAChB,IAAIK,EACJ,IAAMA,EAAI,EAAGA,EAAIX,EAAK,OAAQW,IAC7BX,EAAMW,CAAE,EAAE,OAAS,EAEpBZ,EAAS,CACV,CACD,CAKAnC,EAAO,QAAUiC,KCnXjB,IAAAyB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAU,IAmCVC,GAAiBD,GAAQ,EAK7BD,EAAO,QAAUE,KCnBjB,IAAIC,GAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,GAAU,IAKdF,GAAaC,EAAM,UAAWC,EAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isNonNegativeInteger", "format", "validate", "opts", "options", "require_pool", "__commonJSMin", "exports", "module", "pool", "out", "i", "require_bytes_per_element", "__commonJSMin", "exports", "module", "require_factory", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isCollection", "isTypedArrayLike", "isArrayBuffer", "isComplex64Array", "isComplex128Array", "setReadOnly", "setReadOnlyAccessor", "ctors", "reinterpret64", "reinterpret128", "resolveGetter", "resolveSetter", "ARRAY_DEFAULTS", "format", "ArrayBuffer", "ceil", "floor", "ceil2", "log2", "min", "defaults", "validate", "createPool", "BYTES_PER_ELEMENT", "DEFAULT_DTYPE", "Complex64Array", "Complex128Array", "isCmplx64Array", "arr", "isCmplx128Array", "factory", "options", "nbytes", "pool", "opts", "err", "malloc", "calloc", "free", "clear", "getBytes", "arraybuffer", "n", "buf", "i", "typedarray", "ctor", "len", "dtype", "nargs", "out", "set", "get", "tmp", "p", "require_main", "__commonJSMin", "exports", "module", "factory", "typedarraypool", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5244595..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,347 +0,0 @@ - -{{alias}}( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - Memory is **uninitialized**, which means that the contents of a returned - typed array may contain sensitive contents. - - The function supports the following data types: - - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - The default typed array data type is `float64`. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}() - [] - > arr = {{alias}}( 'float32' ) - [] - - -{{alias}}( length[, dtype] ) - Returns an uninitialized typed array having a specified length from a typed - array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > arr = {{alias}}( 5, 'int32' ) - - - -{{alias}}( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - This method shares the same security vulnerabilities mentioned above. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc() - - > arr = {{alias}}.malloc( 'float32' ) - - - -{{alias}}.malloc( length[, dtype] ) - Returns a typed array having a specified length from a typed array memory - pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc( 5 ) - - > arr = {{alias}}.malloc( 5, 'int32' ) - - - -{{alias}}.malloc( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}.malloc( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.calloc( [dtype] ) - Returns a zero-initialized typed array from a typed array memory pool. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc() - [] - > arr = {{alias}}.calloc( 'float32' ) - [] - - -{{alias}}.calloc( length[, dtype] ) - Returns a zero-initialized typed array having a specified length from a - typed array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}.calloc( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}.free( buf ) - Frees a typed array or typed array buffer for use in a future allocation. - - Parameters - ---------- - buf: TypedArray|ArrayBuffer - Typed array or typed array buffer to free. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ) - - -{{alias}}.clear() - Clears the typed array pool allowing garbage collection of previously - allocated (and currently free) array buffers. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - > {{alias}}.clear() - - -{{alias}}.highWaterMark - Read-only property returning the pool's high water mark. - - Once a high water mark is reached, typed array allocation fails. - - Examples - -------- - > {{alias}}.highWaterMark - - -{{alias}}.nbytes - Read-only property returning the total number of allocated bytes. - - The returned value is the total accumulated value. Hence, anytime a pool - must allocate a new array buffer (i.e., more memory), the pool increments - this value. - - The only time this value is decremented is when a pool is cleared. - - This behavior means that, while allocated buffers which are never freed may, - in fact, be garbage collected, they continue to count against the high water - mark limit. - - Accordingly, you should *always* free allocated buffers in order to prevent - the pool from believing that non-freed buffers are continually in use. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.nbytes - - -{{alias}}.factory( [options] ) - Creates a typed array pool. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.highWaterMark: integer (optional) - Maximum total memory (in bytes) which can be allocated. - - Returns - ------- - fcn: Function - Function for creating typed arrays from a typed array memory pool. - - Examples - -------- - > var pool = {{alias}}.factory(); - > var arr1 = pool( 3, 'float64' ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 4336c42..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,193 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-empty */ -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import typedarraypool = require( './index' ); - - -// TESTS // - -// The function returns a typed array or null... -{ - typedarraypool(); // $ExpectType TypedArrayOrNull - typedarraypool( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the function is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool( true ); // $ExpectError - typedarraypool( false ); // $ExpectError - typedarraypool( null ); // $ExpectError - typedarraypool( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized data type... -{ - typedarraypool( 4, true ); // $ExpectError - typedarraypool( 4, false ); // $ExpectError - typedarraypool( 4, null ); // $ExpectError - typedarraypool( 4, 'abc' ); // $ExpectError - typedarraypool( 4, 123 ); // $ExpectError - typedarraypool( 4, [] ); // $ExpectError - typedarraypool( 4, {} ); // $ExpectError - typedarraypool( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an incorrect number of arguments... -{ - typedarraypool( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `malloc` method which returns a typed array or null... -{ - typedarraypool.malloc(); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.malloc( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `malloc` method is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool.malloc( true ); // $ExpectError - typedarraypool.malloc( false ); // $ExpectError - typedarraypool.malloc( null ); // $ExpectError - typedarraypool.malloc( {} ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.malloc( 4, true ); // $ExpectError - typedarraypool.malloc( 4, false ); // $ExpectError - typedarraypool.malloc( 4, null ); // $ExpectError - typedarraypool.malloc( 4, 'abc' ); // $ExpectError - typedarraypool.malloc( 4, 123 ); // $ExpectError - typedarraypool.malloc( 4, [] ); // $ExpectError - typedarraypool.malloc( 4, {} ); // $ExpectError - typedarraypool.malloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided an incorrect number of arguments... -{ - typedarraypool.malloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `calloc` method which returns a typed array or null... -{ - typedarraypool.calloc(); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `calloc` method is provided a first argument which is not a number... -{ - typedarraypool.calloc( 'abc' ); // $ExpectError - typedarraypool.calloc( true ); // $ExpectError - typedarraypool.calloc( false ); // $ExpectError - typedarraypool.calloc( null ); // $ExpectError - typedarraypool.calloc( {} ); // $ExpectError - typedarraypool.calloc( [] ); // $ExpectError - typedarraypool.calloc( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.calloc( 4, true ); // $ExpectError - typedarraypool.calloc( 4, false ); // $ExpectError - typedarraypool.calloc( 4, null ); // $ExpectError - typedarraypool.calloc( 4, 'abc' ); // $ExpectError - typedarraypool.calloc( 4, 123 ); // $ExpectError - typedarraypool.calloc( 4, [] ); // $ExpectError - typedarraypool.calloc( 4, {} ); // $ExpectError - typedarraypool.calloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided an incorrect number of arguments... -{ - typedarraypool.calloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `factory` method which returns a typed array pool.. -{ - typedarraypool.factory(); // $ExpectType Pool - typedarraypool.factory( { 'highWaterMark': 556 } ); // $ExpectType Pool -} - -// The compiler throws an error if the `factory` method is provided a `highWaterMark` option which is not a number... -{ - typedarraypool.factory( { 'highWaterMark': true } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': false } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': 'abc' } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': null } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': [] } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': {} } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an incorrect number of arguments... -{ - typedarraypool.factory( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` method which returns void... -{ - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.free( arr ); // $ExpectType void -} - -// The compiler throws an error if the `free` method is provided a first argument which is neither a typed array nor array buffer... -{ - typedarraypool.free( true ); // $ExpectError - typedarraypool.free( false ); // $ExpectError - typedarraypool.free( 123 ); // $ExpectError - typedarraypool.free( 'abc' ); // $ExpectError - typedarraypool.free( null ); // $ExpectError - typedarraypool.free( {} ); // $ExpectError - typedarraypool.free( ( x: number ): number => x ); // $ExpectError -} - -// Attached to the main export is a `clear` method which returns void... -{ - typedarraypool.clear(); // $ExpectType void -} - -// The compiler throws an error if the `clear` method is provided arguments... -{ - typedarraypool.clear( {} ); // $ExpectError - typedarraypool.clear( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `highWaterMark` property... -{ - typedarraypool.highWaterMark; // $ExpectType number -} - -// Attached to the main export is a `nbytes` property... -{ - typedarraypool.nbytes; // $ExpectType number -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 24a7846..0000000 --- a/examples/index.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 randu = require( '@stdlib/random-base-randu' ); -var typedarraypool = require( './../lib' ); - -// Create a typed array pool which can allocate at most 1GB: -var typedarray = typedarraypool.factory({ - 'highWaterMark': 1e9 -}); - -// Inspect the pool: -console.log( 'Max bytes: %d', typedarray.highWaterMark ); -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Allocate an array for storing double-precision floating-point numbers: -var arr1 = typedarray( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Fill the array... -var i; -for ( i = 0; i < arr1.length; i++ ) { - arr1[ i ] = randu(); -} - -// Inspect array contents: -console.log( arr1 ); - -// Free the array: -typedarray.free( arr1 ); - -// Allocate another array similar to the previous one: -var arr2 = typedarray( 5, 'float64' ); -// returns - -// Check that we have been returned a new typed array view: -console.log( arr2 === arr1 ); -// => false - -// Inspect array contents: -console.log( arr2 ); - -// Free the array: -typedarray.free( arr2 ); - -// Allocate an initialized array: -var arr3 = typedarray.calloc( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect array contents: -console.log( arr3 ); - -// Free the array: -typedarray.free( arr3 ); - -// Clear the pool: -typedarray.clear(); - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 4254ef5..0f5442f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike, RealOrComplexTypedArray, NumericDataType as DataType } from '@stdlib/types/array'; import ArrayBuffer = require( '@stdlib/array-buffer' ); diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..98685af --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.0-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-setter@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-defaults@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import M from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";function W(e,t){return k(t)?M(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(u("invalid option. `%s` option must be a nonnegative integer. Option: `%s`.","highWaterMark",e.highWaterMark)):null:new TypeError(u("invalid argument. Options argument must be an object. Value: `%s`.",t))}function E(e){var t,r;for(t=[],r=0;rM.highWaterMark?null:(t=new g(e),c+=e,t)}function F(e,t,r){var s;return 0===t?new e(0):null===(s=B(x(t)*T[r]))?s:new e(s,0,t)}function P(){var e,n,i,o,l,c,g,b,v;if(n=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:V,null===(i=d(n)))throw new TypeError(u("invalid argument. Must provide a recognized data type. Value: `%s`.",n));if(e<=0)return new i(0);if(r(arguments[0]))return F(i,arguments[0],n);if(s(arguments[0])){if(b=(o=arguments[0]).length,m(o)?o=p(o,0):a(o)?o=h(o,0):/^complex/.test(n)&&(b/=2),null===(l=F(i,b,n)))return l;if(A(l)||z(l))return l.set(o),l;for(g=f(o),c=j(l),v=0;v0){for(t=v(y(e.byteLength)),t=w(k.length-1,t),r=k[t],s=0;s[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = resolveGetter( arr );\n\t\t\tset = resolveSetter( out );\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["validate","opts","options","isObject","hasOwnProp","highWaterMark","isNonNegativeInteger","TypeError","format","pool","n","out","i","push","DEFAULT_DTYPE","ARRAY_DEFAULTS","get","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","nbytes","err","arguments","length","createPool","ceil","log2","setReadOnly","malloc","calloc","free","clear","setReadOnlyAccessor","getBytes","arraybuffer","buf","pop","ArrayBuffer","typedarray","ctor","len","dtype","ceil2","BYTES_PER_ELEMENT","nargs","set","isString","isCollection","isComplex128Array","reinterpret128","isComplex64Array","reinterpret64","test","resolveGetter","resolveSetter","tmp","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","typedarraypool","main"],"mappings":";;00EAiDA,SAASA,EAAUC,EAAMC,GACxB,OAAMC,EAAUD,GAGXE,EAAYF,EAAS,mBACzBD,EAAKI,cAAgBH,EAAQG,eACvBC,EAAsBL,EAAKI,gBACzB,IAAIE,UAAWC,EAAQ,2EAA4E,gBAAiBP,EAAKI,gBAG3H,KARC,IAAIE,UAAWC,EAAQ,qEAAsEN,GAStG,CC/BA,SAASO,EAAMC,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,iHCcIG,EAAgBC,EAAeC,IAAK,kBACpCC,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASrB,GACjB,IAAIsB,EACAf,EACAR,EACAwB,EAGJ,GADAxB,ECjFO,CACNI,cAAiB,kBDiFbqB,UAAUC,SACdF,EAAMzB,EAAUC,EAAMC,IAErB,MAAMuB,EAaR,OAVAhB,EAAOmB,EAAYC,EAAMC,EAAM7B,EAAKI,iBACpCmB,EAAS,EAETO,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,SAAUC,GAC/BF,EAAaC,EAAQ,OAAQE,GAC7BH,EAAaC,EAAQ,QAASG,GAC9BJ,EAAaC,EAAQ,gBAAiB/B,EAAKI,eAC3C+B,EAAqBJ,EAAQ,SAAUK,GAEhCL,EAQP,SAASK,IACR,OAAOb,CACP,CASD,SAASc,EAAa5B,GACrB,IAAI6B,EACA3B,EAMJ,OAHAA,EAAIkB,EAAMpB,IAGDD,EAAKkB,QAAUlB,EAAMG,GAAIe,OAC1BlB,EAAMG,GAAI4B,MAGbhB,EAAOd,EAAIT,EAAKI,cACb,MAERkC,EAAM,IAAIE,EAAa/B,GAGvBc,GAAUd,EAEH6B,EACP,CAWD,SAASG,EAAYC,EAAMC,EAAKC,GAC/B,IAAIN,EACJ,OAAa,IAARK,EACG,IAAID,EAAM,GAGL,QADbJ,EAAMD,EAAaQ,EAAOF,GAAMG,EAAmBF,KAE3CN,EAED,IAAII,EAAMJ,EAAK,EAAGK,EACzB,CAkBD,SAASZ,IACR,IAAIgB,EACAH,EACAF,EACAtB,EACAV,EACAsC,EACAjC,EACA4B,EACAhC,EAUJ,GALCiC,GAHDG,EAAQtB,UAAUC,SACJuB,EAAUxB,UAAWsB,EAAM,IAEhCtB,UADRsB,GAAS,GAGDlC,EAGK,QADd6B,EAAOzB,EAAO2B,IAEb,MAAM,IAAItC,UAAWC,EAAQ,sEAAuEqC,IAErG,GAAKG,GAAS,EACb,OAAO,IAAIL,EAAM,GAGlB,GAAKrC,EAAsBoB,UAAW,IACrC,OAAOgB,EAAYC,EAAMjB,UAAW,GAAKmB,GAG1C,GAAKM,EAAczB,UAAW,IAAQ,CAYrC,GAVAkB,GADAvB,EAAMK,UAAW,IACPC,OACLyB,EAAmB/B,GACvBA,EAAMgC,EAAgBhC,EAAK,GAChBiC,EAAkBjC,GAC7BA,EAAMkC,EAAelC,EAAK,GACf,WAAWmC,KAAMX,KAE5BD,GAAO,GAGK,QADbjC,EAAM+B,EAAYC,EAAMC,EAAKC,IAE5B,OAAOlC,EAER,GAAKW,EAAiBX,IAASS,EAAgBT,GAE9C,OADAA,EAAIsC,IAAK5B,GACFV,EAKR,IAFAK,EAAMyC,EAAepC,GACrB4B,EAAMS,EAAe/C,GACfC,EAAI,EAAGA,EAAIgC,EAAKhC,IACrBqC,EAAKtC,EAAKC,EAAGI,EAAKK,EAAKT,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,wGAAyGkB,UAAW,IACjJ,CAgBD,SAASO,IACR,IAAIe,EACArC,EACAgD,EACA/C,EAUJ,GAAa,QANZD,EADc,KADfqC,EAAQtB,UAAUC,QAEXK,IACe,IAAVgB,EACLhB,EAAQN,UAAW,IAEnBM,EAAQN,UAAW,GAAKA,UAAW,KAWzC,IANCiC,EADIrC,EAAiBX,GACf0C,EAAgB1C,EAAK,GAChBS,EAAgBT,GACrB4C,EAAe5C,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAI+C,EAAIhC,OAAQf,IAC5B+C,EAAK/C,GAAM,EAGb,OAAOD,CACP,CAcD,SAASuB,EAAMK,GACd,IAAI7B,EACAkD,EACAhD,EACJ,GAAKiD,EAAkBtB,IAASA,EAAIuB,OACnCvB,EAAMA,EAAIuB,YACJ,IAAMC,EAAexB,GAC3B,MAAM,IAAIhC,UAAWC,EAAQ,4EAA6E+B,IAE3G,GAAKA,EAAIyB,WAAa,EAAI,CAQzB,IAPAtD,EAAIuD,EAAOnC,EAAMS,EAAIyB,aAGrBtD,EAAIwD,EAAKzD,EAAKkB,OAAO,EAAGjB,GAGxBkD,EAAInD,EAAMC,GACJE,EAAI,EAAGA,EAAIgD,EAAEjC,OAAQf,IAC1B,GAAKgD,EAAGhD,KAAQ2B,EACf,OAAO,EAITqB,EAAE/C,KAAM0B,EACR,CACD,OAAO,CACP,CAOD,SAASJ,IACR,IAAIvB,EACJ,IAAMA,EAAI,EAAGA,EAAIH,EAAKkB,OAAQf,IAC7BH,EAAMG,GAAIe,OAAS,EAEpBH,EAAS,CACT,CACF,CErTG,IAAC2C,EAAiB5C,ICPrBQ,EAAAqC,EAAA,UAAA7C"} \ No newline at end of file diff --git a/lib/bytes_per_element.json b/lib/bytes_per_element.json deleted file mode 100644 index f97fe70..0000000 --- a/lib/bytes_per_element.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "float64": 8, - "float32": 4, - "int16": 2, - "int32": 4, - "int8": 1, - "uint16": 2, - "uint32": 4, - "uint8": 1, - "uint8c": 1, - "complex64": 8, - "complex128": 16 -} diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index a421711..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +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'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'highWaterMark': 9007199254740992 - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 4365791..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,372 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var isComplex64Array = require( '@stdlib/assert-is-complex64array' ); -var isComplex128Array = require( '@stdlib/assert-is-complex128array' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var ctors = require( '@stdlib/array-typed-ctors' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var resolveSetter = require( '@stdlib/array-base-resolve-setter' ); -var ARRAY_DEFAULTS = require( '@stdlib/array-defaults' ); -var format = require( '@stdlib/string-format' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil = require( '@stdlib/math-base-special-ceil' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); -var log2 = require( '@stdlib/math-base-special-log2' ); -var min = require( '@stdlib/math-base-special-min' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var createPool = require( './pool.js' ); -var BYTES_PER_ELEMENT = require( './bytes_per_element.json' ); - - -// VARIABLES // - -var DEFAULT_DTYPE = ARRAY_DEFAULTS.get( 'dtypes.default' ); -var Complex64Array = ctors( 'complex64' ); -var Complex128Array = ctors( 'complex128' ); - - -// FUNCTIONS // - -/** -* Tests whether an array is a single-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a single-precision complex floating-point number array -*/ -function isCmplx64Array( arr ) { - return ( arr instanceof Complex64Array ); -} - -/** -* Tests whether an array is a double-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a double-precision complex floating-point number array -*/ -function isCmplx128Array( arr ) { - return ( arr instanceof Complex128Array ); -} - - -// MAIN // - -/** -* Creates a typed array pool. -* -* @param {Options} [options] - pool options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} allocator -* -* @example -* var typedarraypool = factory(); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -function factory( options ) { - var nbytes; - var pool; - var opts; - var err; - - opts = defaults(); - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - pool = createPool( ceil( log2( opts.highWaterMark ) ) ); - nbytes = 0; - - setReadOnly( malloc, 'malloc', malloc ); // circular reference - setReadOnly( malloc, 'calloc', calloc ); - setReadOnly( malloc, 'free', free ); - setReadOnly( malloc, 'clear', clear ); - setReadOnly( malloc, 'highWaterMark', opts.highWaterMark ); - setReadOnlyAccessor( malloc, 'nbytes', getBytes ); - - return malloc; - - /** - * Returns the number of allocated bytes. - * - * @private - * @returns {NonNegativeInteger} number of allocated bytes - */ - function getBytes() { - return nbytes; - } - - /** - * Returns an array buffer. - * - * @private - * @param {NonNegativeInteger} n - number of bytes - * @returns {(ArrayBuffer|null)} array buffer or null - */ - function arraybuffer( n ) { - var buf; - var i; - - // Convert the number of bytes to an index in our pool table: - i = log2( n ); - - // If we already have an available array buffer, use it... - if ( i < pool.length && pool[ i ].length ) { - return pool[ i ].pop(); - } - // Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate... - if ( nbytes+n > opts.highWaterMark ) { - return null; - } - buf = new ArrayBuffer( n ); - - // Update the running counter of allocated bytes: - nbytes += n; - - return buf; - } - - /** - * Returns a typed array. - * - * @private - * @param {Function} ctor - typed array constructor - * @param {NonNegativeInteger} len - view length - * @param {string} dtype - data type - * @returns {(TypedArray|null)} typed array or null - */ - function typedarray( ctor, len, dtype ) { - var buf; - if ( len === 0 ) { - return new ctor( 0 ); - } - buf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] ); - if ( buf === null ) { - return buf; - } - return new ctor( buf, 0, len ); - } - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length or an array-like object - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function malloc() { - var nargs; - var dtype; - var ctor; - var arr; - var out; - var set; - var get; - var len; - var i; - - nargs = arguments.length; - if ( nargs && isString( arguments[ nargs-1 ] ) ) { - nargs -= 1; - dtype = arguments[ nargs ]; - } else { - dtype = DEFAULT_DTYPE; - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) ); - } - if ( nargs <= 0 ) { - return new ctor( 0 ); - } - // Check if provided a typed array length... - if ( isNonNegativeInteger( arguments[ 0 ] ) ) { - return typedarray( ctor, arguments[ 0 ], dtype ); - } - // Check if provided an array-like object containing data elements... - if ( isCollection( arguments[ 0 ] ) ) { - arr = arguments[ 0 ]; - len = arr.length; - if ( isComplex128Array( arr ) ) { - arr = reinterpret128( arr, 0 ); - } else if ( isComplex64Array( arr ) ) { - arr = reinterpret64( arr, 0 ); - } else if ( /^complex/.test( dtype ) ) { - // Assume we've been provided an array of interleaved real and imaginary components... - len /= 2; - } - out = typedarray( ctor, len, dtype ); - if ( out === null ) { - return out; - } - if ( isCmplx128Array( out ) || isCmplx64Array( out ) ) { - out.set( arr ); - return out; - } - // Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other "unsafe" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things... - get = resolveGetter( arr ); - set = resolveSetter( out ); - for ( i = 0; i < len; i++ ) { - set( out, i, get( arr, i ) ); - } - return out; - } - throw new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) ); - } - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {NonNegativeInteger} [len=0] - array length - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function calloc() { - var nargs; - var out; - var tmp; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - out = malloc(); - } else if ( nargs === 1 ) { - out = malloc( arguments[ 0 ] ); - } else { - out = malloc( arguments[ 0 ], arguments[ 1 ] ); - } - if ( out !== null ) { - // Initialize the memory... - if ( isCmplx128Array( out ) ) { - tmp = reinterpret128( out, 0 ); - } else if ( isCmplx64Array( out ) ) { - tmp = reinterpret64( out, 0 ); - } else { - tmp = out; - } - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = 0.0; - } - } - return out; - } - - /** - * Frees a typed array or typed array buffer. - * - * ## Notes - * - * - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., "freeing" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool. - * - * @private - * @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free - * @throws {TypeError} must provide a typed array or typed array buffer - * @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed - */ - function free( buf ) { - var n; - var p; - var i; - if ( isTypedArrayLike( buf ) && buf.buffer ) { - buf = buf.buffer; - } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) ); - } - if ( buf.byteLength > 0 ) { - n = floor( log2( buf.byteLength ) ); - - // Prohibit "freeing" array buffers which would potentially allow users to circumvent high water mark limits: - n = min( pool.length-1, n ); - - // Ensure that we do not attempt to free the same buffer more than once... - p = pool[ n ]; - for ( i = 0; i < p.length; i++ ) { - if ( p[ i ] === buf ) { - return false; - } - } - // Add the buffer to our pool of free buffers: - p.push( buf ); - } - return true; - } - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @private - */ - function clear() { - var i; - for ( i = 0; i < pool.length; i++ ) { - pool[ i ].length = 0; - } - nbytes = 0; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6c12a4e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Typed array pool. -* -* @module @stdlib/array-pool -* -* @example -* var typedarraypool = require( '@stdlib/array-pool' ); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8f69ee3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,63 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @name typedarraypool -* @type {Function} -* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a valid array length or an array-like object -* @throws {TypeError} must provide a recognized data type -* @returns {(TypedArray|null)} typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -var typedarraypool = factory(); - - -// EXPORTS // - -module.exports = typedarraypool; diff --git a/lib/pool.js b/lib/pool.js deleted file mode 100644 index 5abd287..0000000 --- a/lib/pool.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Initializes a cache for pooled typed array buffers. -* -* @private -* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size -* @returns {ArrayArray} initialized cache -*/ -function pool( n ) { - var out; - var i; - - out = []; - for ( i = 0; i < n+1; i++ ) { - out.push( [] ); - } - return out; -} - - -// EXPORTS // - -module.exports = pool; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index ce54890..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'highWaterMark': 1024 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'highWaterMark' ) ) { - opts.highWaterMark = options.highWaterMark; - if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 7fa2632..6a56004 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.0", "description": "Typed array pool.", "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,77 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-resolve-getter": "^0.2.0", - "@stdlib/array-base-resolve-setter": "^0.2.0", - "@stdlib/array-buffer": "^0.2.0", - "@stdlib/array-defaults": "^0.2.0", - "@stdlib/array-typed-ctors": "^0.2.0", - "@stdlib/assert-has-own-property": "^0.2.0", - "@stdlib/assert-is-arraybuffer": "^0.2.0", - "@stdlib/assert-is-collection": "^0.2.0", - "@stdlib/assert-is-complex128array": "^0.2.0", - "@stdlib/assert-is-complex64array": "^0.2.0", - "@stdlib/assert-is-nonnegative-integer": "^0.2.0", - "@stdlib/assert-is-plain-object": "^0.2.0", - "@stdlib/assert-is-string": "^0.2.0", - "@stdlib/assert-is-typed-array-like": "^0.2.0", - "@stdlib/math-base-special-ceil": "^0.2.0", - "@stdlib/math-base-special-ceil2": "^0.2.0", - "@stdlib/math-base-special-floor": "^0.2.0", - "@stdlib/math-base-special-log2": "^0.2.0", - "@stdlib/math-base-special-min": "^0.2.0", - "@stdlib/strided-base-reinterpret-complex128": "^0.2.0", - "@stdlib/strided-base-reinterpret-complex64": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.0", - "@stdlib/types": "^0.3.1", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.0", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.1.0", - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-float32": "^0.2.0", - "@stdlib/array-float64": "^0.2.0", - "@stdlib/array-int16": "^0.2.0", - "@stdlib/array-int32": "^0.2.0", - "@stdlib/array-int8": "^0.2.0", - "@stdlib/array-uint16": "^0.2.0", - "@stdlib/array-uint32": "^0.2.0", - "@stdlib/array-uint8": "^0.2.0", - "@stdlib/array-uint8c": "^0.2.0", - "@stdlib/assert-instance-of": "^0.2.0", - "@stdlib/assert-is-complex-typed-array": "^0.2.0", - "@stdlib/assert-is-function": "^0.2.0", - "@stdlib/assert-is-typed-array": "^0.2.0", - "@stdlib/complex-float32": "^0.2.0", - "@stdlib/complex-float64": "^0.2.0", - "@stdlib/complex-imag": "^0.2.0", - "@stdlib/complex-imagf": "^0.2.0", - "@stdlib/complex-real": "^0.2.0", - "@stdlib/complex-realf": "^0.2.0", - "@stdlib/math-base-special-pow": "^0.2.0", - "@stdlib/random-base-randu": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.0" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..4e6883a --- /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.factory.js b/test/test.factory.js deleted file mode 100644 index 396aee2..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,2240 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function (no options)', function test( t ) { - t.strictEqual( typeof factory(), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - t.strictEqual( typeof factory( {} ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided a `highWaterMark` option which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (length)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a function which returns a typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, length)', function test( t ) { - var typedarraypool = factory(); - var arr; - - arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a `malloc` method which is a circular reference', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - var buf; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the returned function is a property which returns the pool\'s high water mark', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function supports specifying a high water mark which limits the total amount of memory a pool can allocate', function test( t ) { - var typedarraypool; - var arr1; - var arr2; - - typedarraypool = factory({ - 'highWaterMark': 64 // bytes - }); - - typedarraypool.clear(); - - arr1 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr1.length, 8, 'returns expected value' ); - t.strictEqual( arr1.byteLength, 64, 'returns expected value' ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - typedarraypool.free( arr1 ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Create an array which is less than or equal to the high water mark: - arr2 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr2.length, 8, 'returns expected value' ); - t.strictEqual( arr2.byteLength, 64, 'returns expected value' ); - - typedarraypool.free( arr2 ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a property which returns the total number of accumulated bytes', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var typedarraypool; - var arrs; - var i; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 54aa5ee..0000000 --- a/test/test.js +++ /dev/null @@ -1,1797 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var typedarraypool = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -}); From 45d0e1894deac2177025708aa5e269c189404425 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 06:25:36 +0000 Subject: [PATCH 070/103] Update README.md for ESM bundle v0.2.0 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ab1b1af..cc47b44 100644 --- a/README.md +++ b/README.md @@ -52,13 +52,13 @@ limitations under the License. ## Usage ```javascript -import typedarraypool from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-pool@esm/index.mjs'; +import typedarraypool from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-pool@v0.2.0-esm/index.mjs'; ``` You can also import the following named exports from the package: ```javascript -import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-pool@esm/index.mjs'; +import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-pool@v0.2.0-esm/index.mjs'; ``` #### typedarraypool( \[dtype] ) @@ -392,7 +392,7 @@ pool.free( arr ); - - - - From bc1b4d74b1ef6a1d5ed6c6760fbd6744ddd67d89 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 20:50:35 +0000 Subject: [PATCH 074/103] 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 | 45 +- SECURITY.md | 5 - benchmark/benchmark.calloc.js | 246 -- benchmark/benchmark.factory.js | 71 - benchmark/benchmark.js | 246 -- benchmark/benchmark.length.complex128.js | 102 - benchmark/benchmark.length.complex64.js | 102 - benchmark/benchmark.length.float32.js | 102 - benchmark/benchmark.length.float64.js | 102 - benchmark/benchmark.length.int16.js | 102 - benchmark/benchmark.length.int32.js | 102 - benchmark/benchmark.length.int8.js | 102 - benchmark/benchmark.length.uint16.js | 102 - benchmark/benchmark.length.uint32.js | 102 - benchmark/benchmark.length.uint8.js | 102 - benchmark/benchmark.length.uint8c.js | 102 - benchmark/benchmark.malloc.js | 246 -- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 347 -- docs/types/test.ts | 193 - examples/index.js | 80 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/bytes_per_element.json | 13 - lib/defaults.js | 42 - lib/factory.js | 372 -- lib/index.js | 56 - lib/main.js | 63 - lib/pool.js | 44 - lib/validate.js | 66 - package.json | 99 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 2240 ---------- test/test.js | 1797 -------- 62 files changed, 4871 insertions(+), 10645 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.calloc.js delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.complex128.js delete mode 100644 benchmark/benchmark.length.complex64.js delete mode 100644 benchmark/benchmark.length.float32.js delete mode 100644 benchmark/benchmark.length.float64.js delete mode 100644 benchmark/benchmark.length.int16.js delete mode 100644 benchmark/benchmark.length.int32.js delete mode 100644 benchmark/benchmark.length.int8.js delete mode 100644 benchmark/benchmark.length.uint16.js delete mode 100644 benchmark/benchmark.length.uint32.js delete mode 100644 benchmark/benchmark.length.uint8.js delete mode 100644 benchmark/benchmark.length.uint8c.js delete mode 100644 benchmark/benchmark.malloc.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/bytes_per_element.json delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/pool.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ea35f20..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/array/pool) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6f7c875..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/array/pool) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 869c4e9..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -495,7 +492,7 @@ console.log( 'nbytes: %d', typedarray.nbytes ); ## 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]. @@ -564,7 +561,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/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.calloc.js b/benchmark/benchmark.calloc.js deleted file mode 100644 index fd8f53d..0000000 --- a/benchmark/benchmark.calloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':calloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 58918bb..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = typedarray.factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:highWaterMark', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'highWaterMark': 0 - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.highWaterMark = i; - f = typedarray.factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 4310559..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.complex128.js b/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 12c6668..0000000 --- a/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex64.js b/benchmark/benchmark.length.complex64.js deleted file mode 100644 index ca2b45c..0000000 --- a/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float32.js b/benchmark/benchmark.length.float32.js deleted file mode 100644 index b3b4508..0000000 --- a/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float64.js b/benchmark/benchmark.length.float64.js deleted file mode 100644 index 5f0132d..0000000 --- a/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int16.js b/benchmark/benchmark.length.int16.js deleted file mode 100644 index 9f253cb..0000000 --- a/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int32.js b/benchmark/benchmark.length.int32.js deleted file mode 100644 index f83e795..0000000 --- a/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int8.js b/benchmark/benchmark.length.int8.js deleted file mode 100644 index 5b01174..0000000 --- a/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint16.js b/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 32b0a5d..0000000 --- a/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint32.js b/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 290b90c..0000000 --- a/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8.js b/benchmark/benchmark.length.uint8.js deleted file mode 100644 index ff7d733..0000000 --- a/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8c.js b/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index 8f0d10a..0000000 --- a/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.malloc.js b/benchmark/benchmark.malloc.js deleted file mode 100644 index 1661907..0000000 --- a/benchmark/benchmark.malloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':malloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 612de17..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/array/pool" -%% click B href "https://github.com/stdlib-js/array-pool/tree/main" -%% click C href "https://github.com/stdlib-js/array-pool/tree/production" -%% click D href "https://github.com/stdlib-js/array-pool/tree/esm" -%% click E href "https://github.com/stdlib-js/array-pool/tree/deno" -%% click F href "https://github.com/stdlib-js/array-pool/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/pool -[production-url]: https://github.com/stdlib-js/array-pool/tree/production -[deno-url]: https://github.com/stdlib-js/array-pool/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-pool/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-pool/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-pool/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-pool/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-pool/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 5160b6f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import typedarraypool from '../docs/types/index'; -export = typedarraypool; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4f5b474..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var l=function(n,i){return function(){return i||n((i={exports:{}}).exports,i),i.exports}};var M=l(function(Er,w){ -function I(){return{highWaterMark:9007199254740992}}w.exports=I -});var T=l(function(Tr,E){ -var U=require('@stdlib/assert-is-plain-object/dist'),z=require('@stdlib/assert-has-own-property/dist'),G=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,k=require('@stdlib/error-tools-fmtprodmsg/dist');function H(n,i){return U(i)?z(i,"highWaterMark")&&(n.highWaterMark=i.highWaterMark,!G(n.highWaterMark))?new TypeError(k('01H2t',"highWaterMark",n.highWaterMark)):null:new TypeError(k('01H2V',i));}E.exports=H -});var C=l(function(Wr,W){ -function J(n){var i,u;for(i=[],u=0;uv.highWaterMark?null:(e=new or(r),i+=r,e)}function d(r,e,a){var t;return e===0?new r(0):(t=j(vr(e)*mr[a]),t===null?t:new r(t,0,e))}function o(){var r,e,a,t,s,x,A,c,f;if(r=arguments.length,r&&Q(arguments[r-1])?(r-=1,e=arguments[r]):e=pr,a=y(e),a===null)throw new TypeError(m('01H2Y',e));if(r<=0)return new a(0);if(X(arguments[0]))return d(a,arguments[0],e);if(Z(arguments[0])){if(t=arguments[0],c=t.length,tr(t)?t=b(t,0):er(t)?t=P(t,0):/^complex/.test(e)&&(c/=2),s=d(a,c,e),s===null)return s;if(R(s)||L(s))return s.set(t),s;for(A=ir(t),x=nr(s),f=0;f0){for(e=lr(p(r.byteLength)),e=fr(u.length-1,e),a=u[e],t=0;t[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = resolveGetter( arr );\n\t\t\tset = resolveSetter( out );\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nmodule.exports = typedarraypool;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* var typedarraypool = require( '@stdlib/array-pool' );\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,cAAiB,gBAClB,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,eAAgB,IACzCD,EAAK,cAAgBC,EAAQ,cACxB,CAACJ,EAAsBG,EAAK,aAAc,GACvC,IAAI,UAAWF,EAAQ,2EAA4E,gBAAiBE,EAAK,aAAc,CAAE,EAG3I,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cA6BA,SAASC,EAAM,EAAI,CAClB,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAI,EAAE,EAAGA,IACrBD,EAAI,KAAM,CAAC,CAAE,EAEd,OAAOA,CACR,CAKAF,EAAO,QAAUC,IC3CjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,QAAW,EACX,QAAW,EACX,MAAS,EACT,MAAS,EACT,KAAQ,EACR,OAAU,EACV,OAAU,EACV,MAAS,EACT,OAAU,EACT,UAAa,EACb,WAAc,EAChB,ICZA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAe,QAAS,8BAA+B,EACvDC,EAAmB,QAAS,oCAAqC,EACjEC,GAAgB,QAAS,+BAAgC,EACzDC,GAAmB,QAAS,kCAAmC,EAC/DC,GAAoB,QAAS,mCAAoC,EACjEC,EAAc,QAAS,uDAAwD,EAC/EC,GAAsB,QAAS,uDAAwD,EACvFC,EAAQ,QAAS,2BAA4B,EAC7CC,EAAgB,QAAS,4CAA6C,EACtEC,EAAiB,QAAS,6CAA8C,EACxEC,GAAgB,QAAS,mCAAoC,EAC7DC,GAAgB,QAAS,mCAAoC,EAC7DC,GAAiB,QAAS,wBAAyB,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,GAAc,QAAS,sBAAuB,EAC9CC,GAAO,QAAS,gCAAiC,EACjDC,GAAQ,QAAS,iCAAkC,EACnDC,GAAQ,QAAS,iCAAkC,EACnDC,EAAO,QAAS,gCAAiC,EACjDC,GAAM,QAAS,+BAAgC,EAC/CC,GAAW,IACXC,GAAW,IACXC,GAAa,IACbC,GAAoB,IAKpBC,GAAgBZ,GAAe,IAAK,gBAAiB,EACrDa,GAAiBlB,EAAO,WAAY,EACpCmB,GAAkBnB,EAAO,YAAa,EAY1C,SAASoB,EAAgBC,EAAM,CAC9B,OAASA,aAAeH,EACzB,CASA,SAASI,EAAiBD,EAAM,CAC/B,OAASA,aAAeF,EACzB,CA6BA,SAASI,GAASC,EAAU,CAC3B,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,EAAOd,GAAS,EACX,UAAU,SACde,EAAMd,GAAUa,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAAF,EAAOX,GAAYP,GAAMG,EAAMgB,EAAK,aAAc,CAAE,CAAE,EACtDF,EAAS,EAET3B,EAAa+B,EAAQ,SAAUA,CAAO,EACtC/B,EAAa+B,EAAQ,SAAUC,CAAO,EACtChC,EAAa+B,EAAQ,OAAQE,CAAK,EAClCjC,EAAa+B,EAAQ,QAASG,CAAM,EACpClC,EAAa+B,EAAQ,gBAAiBF,EAAK,aAAc,EACzD5B,GAAqB8B,EAAQ,SAAUI,CAAS,EAEzCJ,EAQP,SAASI,GAAW,CACnB,OAAOR,CACR,CASA,SAASS,EAAaC,EAAI,CACzB,IAAIC,EACAC,EAMJ,OAHAA,EAAI1B,EAAMwB,CAAE,EAGPE,EAAIX,EAAK,QAAUA,EAAMW,CAAE,EAAE,OAC1BX,EAAMW,CAAE,EAAE,IAAI,EAGjBZ,EAAOU,EAAIR,EAAK,cACb,MAERS,EAAM,IAAI7B,GAAa4B,CAAE,EAGzBV,GAAUU,EAEHC,EACR,CAWA,SAASE,EAAYC,EAAMC,EAAKC,EAAQ,CACvC,IAAIL,EACJ,OAAKI,IAAQ,EACL,IAAID,EAAM,CAAE,GAEpBH,EAAMF,EAAaxB,GAAO8B,CAAI,EAAExB,GAAmByB,CAAM,CAAE,EACtDL,IAAQ,KACLA,EAED,IAAIG,EAAMH,EAAK,EAAGI,CAAI,EAC9B,CAkBA,SAASX,GAAS,CACjB,IAAIa,EACAD,EACAF,EACAlB,EACAsB,EACAC,EACAC,EACAL,EACAH,EAUJ,GARAK,EAAQ,UAAU,OACbA,GAASnD,EAAU,UAAWmD,EAAM,CAAE,CAAE,GAC5CA,GAAS,EACTD,EAAQ,UAAWC,CAAM,GAEzBD,EAAQxB,GAETsB,EAAOvC,EAAOyC,CAAM,EACfF,IAAS,KACb,MAAM,IAAI,UAAWjC,EAAQ,sEAAuEmC,CAAM,CAAE,EAE7G,GAAKC,GAAS,EACb,OAAO,IAAIH,EAAM,CAAE,EAGpB,GAAK/C,EAAsB,UAAW,CAAE,CAAE,EACzC,OAAO8C,EAAYC,EAAM,UAAW,CAAE,EAAGE,CAAM,EAGhD,GAAKhD,EAAc,UAAW,CAAE,CAAE,EAAI,CAYrC,GAXA4B,EAAM,UAAW,CAAE,EACnBmB,EAAMnB,EAAI,OACLxB,GAAmBwB,CAAI,EAC3BA,EAAMnB,EAAgBmB,EAAK,CAAE,EAClBzB,GAAkByB,CAAI,EACjCA,EAAMpB,EAAeoB,EAAK,CAAE,EACjB,WAAW,KAAMoB,CAAM,IAElCD,GAAO,GAERG,EAAML,EAAYC,EAAMC,EAAKC,CAAM,EAC9BE,IAAQ,KACZ,OAAOA,EAER,GAAKrB,EAAiBqB,CAAI,GAAKvB,EAAgBuB,CAAI,EAClD,OAAAA,EAAI,IAAKtB,CAAI,EACNsB,EAKR,IAFAE,EAAM1C,GAAekB,CAAI,EACzBuB,EAAMxC,GAAeuC,CAAI,EACnBN,EAAI,EAAGA,EAAIG,EAAKH,IACrBO,EAAKD,EAAKN,EAAGQ,EAAKxB,EAAKgB,CAAE,CAAE,EAE5B,OAAOM,CACR,CACA,MAAM,IAAI,UAAWrC,EAAQ,wGAAyG,UAAW,CAAE,CAAE,CAAE,CACxJ,CAgBA,SAASwB,GAAS,CACjB,IAAIY,EACAC,EACAG,EACAT,EAUJ,GARAK,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAMd,EAAO,EACFa,IAAU,EACrBC,EAAMd,EAAQ,UAAW,CAAE,CAAE,EAE7Bc,EAAMd,EAAQ,UAAW,CAAE,EAAG,UAAW,CAAE,CAAE,EAEzCc,IAAQ,KASZ,IAPKrB,EAAiBqB,CAAI,EACzBG,EAAM5C,EAAgByC,EAAK,CAAE,EAClBvB,EAAgBuB,CAAI,EAC/BG,EAAM7C,EAAe0C,EAAK,CAAE,EAE5BG,EAAMH,EAEDN,EAAI,EAAGA,EAAIS,EAAI,OAAQT,IAC5BS,EAAKT,CAAE,EAAI,EAGb,OAAOM,CACR,CAcA,SAASZ,EAAMK,EAAM,CACpB,IAAID,EACAY,EACAV,EACJ,GAAK3C,EAAkB0C,CAAI,GAAKA,EAAI,OACnCA,EAAMA,EAAI,eACC,CAACzC,GAAeyC,CAAI,EAC/B,MAAM,IAAI,UAAW9B,EAAQ,4EAA6E8B,CAAI,CAAE,EAEjH,GAAKA,EAAI,WAAa,EAAI,CAQzB,IAPAD,EAAI1B,GAAOE,EAAMyB,EAAI,UAAW,CAAE,EAGlCD,EAAIvB,GAAKc,EAAK,OAAO,EAAGS,CAAE,EAG1BY,EAAIrB,EAAMS,CAAE,EACNE,EAAI,EAAGA,EAAIU,EAAE,OAAQV,IAC1B,GAAKU,EAAGV,CAAE,IAAMD,EACf,MAAO,GAITW,EAAE,KAAMX,CAAI,CACb,CACA,MAAO,EACR,CAOA,SAASJ,GAAQ,CAChB,IAAIK,EACJ,IAAMA,EAAI,EAAGA,EAAIX,EAAK,OAAQW,IAC7BX,EAAMW,CAAE,EAAE,OAAS,EAEpBZ,EAAS,CACV,CACD,CAKAnC,EAAO,QAAUiC,KCnXjB,IAAAyB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAU,IAmCVC,GAAiBD,GAAQ,EAK7BD,EAAO,QAAUE,KCnBjB,IAAIC,GAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,GAAU,IAKdF,GAAaC,EAAM,UAAWC,EAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isNonNegativeInteger", "format", "validate", "opts", "options", "require_pool", "__commonJSMin", "exports", "module", "pool", "out", "i", "require_bytes_per_element", "__commonJSMin", "exports", "module", "require_factory", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isCollection", "isTypedArrayLike", "isArrayBuffer", "isComplex64Array", "isComplex128Array", "setReadOnly", "setReadOnlyAccessor", "ctors", "reinterpret64", "reinterpret128", "resolveGetter", "resolveSetter", "ARRAY_DEFAULTS", "format", "ArrayBuffer", "ceil", "floor", "ceil2", "log2", "min", "defaults", "validate", "createPool", "BYTES_PER_ELEMENT", "DEFAULT_DTYPE", "Complex64Array", "Complex128Array", "isCmplx64Array", "arr", "isCmplx128Array", "factory", "options", "nbytes", "pool", "opts", "err", "malloc", "calloc", "free", "clear", "getBytes", "arraybuffer", "n", "buf", "i", "typedarray", "ctor", "len", "dtype", "nargs", "out", "set", "get", "tmp", "p", "require_main", "__commonJSMin", "exports", "module", "factory", "typedarraypool", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5244595..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,347 +0,0 @@ - -{{alias}}( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - Memory is **uninitialized**, which means that the contents of a returned - typed array may contain sensitive contents. - - The function supports the following data types: - - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - The default typed array data type is `float64`. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}() - [] - > arr = {{alias}}( 'float32' ) - [] - - -{{alias}}( length[, dtype] ) - Returns an uninitialized typed array having a specified length from a typed - array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > arr = {{alias}}( 5, 'int32' ) - - - -{{alias}}( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - This method shares the same security vulnerabilities mentioned above. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc() - - > arr = {{alias}}.malloc( 'float32' ) - - - -{{alias}}.malloc( length[, dtype] ) - Returns a typed array having a specified length from a typed array memory - pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc( 5 ) - - > arr = {{alias}}.malloc( 5, 'int32' ) - - - -{{alias}}.malloc( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}.malloc( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.calloc( [dtype] ) - Returns a zero-initialized typed array from a typed array memory pool. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc() - [] - > arr = {{alias}}.calloc( 'float32' ) - [] - - -{{alias}}.calloc( length[, dtype] ) - Returns a zero-initialized typed array having a specified length from a - typed array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}.calloc( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}.free( buf ) - Frees a typed array or typed array buffer for use in a future allocation. - - Parameters - ---------- - buf: TypedArray|ArrayBuffer - Typed array or typed array buffer to free. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ) - - -{{alias}}.clear() - Clears the typed array pool allowing garbage collection of previously - allocated (and currently free) array buffers. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - > {{alias}}.clear() - - -{{alias}}.highWaterMark - Read-only property returning the pool's high water mark. - - Once a high water mark is reached, typed array allocation fails. - - Examples - -------- - > {{alias}}.highWaterMark - - -{{alias}}.nbytes - Read-only property returning the total number of allocated bytes. - - The returned value is the total accumulated value. Hence, anytime a pool - must allocate a new array buffer (i.e., more memory), the pool increments - this value. - - The only time this value is decremented is when a pool is cleared. - - This behavior means that, while allocated buffers which are never freed may, - in fact, be garbage collected, they continue to count against the high water - mark limit. - - Accordingly, you should *always* free allocated buffers in order to prevent - the pool from believing that non-freed buffers are continually in use. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.nbytes - - -{{alias}}.factory( [options] ) - Creates a typed array pool. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.highWaterMark: integer (optional) - Maximum total memory (in bytes) which can be allocated. - - Returns - ------- - fcn: Function - Function for creating typed arrays from a typed array memory pool. - - Examples - -------- - > var pool = {{alias}}.factory(); - > var arr1 = pool( 3, 'float64' ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 4336c42..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,193 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-empty */ -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import typedarraypool = require( './index' ); - - -// TESTS // - -// The function returns a typed array or null... -{ - typedarraypool(); // $ExpectType TypedArrayOrNull - typedarraypool( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the function is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool( true ); // $ExpectError - typedarraypool( false ); // $ExpectError - typedarraypool( null ); // $ExpectError - typedarraypool( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized data type... -{ - typedarraypool( 4, true ); // $ExpectError - typedarraypool( 4, false ); // $ExpectError - typedarraypool( 4, null ); // $ExpectError - typedarraypool( 4, 'abc' ); // $ExpectError - typedarraypool( 4, 123 ); // $ExpectError - typedarraypool( 4, [] ); // $ExpectError - typedarraypool( 4, {} ); // $ExpectError - typedarraypool( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an incorrect number of arguments... -{ - typedarraypool( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `malloc` method which returns a typed array or null... -{ - typedarraypool.malloc(); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.malloc( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `malloc` method is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool.malloc( true ); // $ExpectError - typedarraypool.malloc( false ); // $ExpectError - typedarraypool.malloc( null ); // $ExpectError - typedarraypool.malloc( {} ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.malloc( 4, true ); // $ExpectError - typedarraypool.malloc( 4, false ); // $ExpectError - typedarraypool.malloc( 4, null ); // $ExpectError - typedarraypool.malloc( 4, 'abc' ); // $ExpectError - typedarraypool.malloc( 4, 123 ); // $ExpectError - typedarraypool.malloc( 4, [] ); // $ExpectError - typedarraypool.malloc( 4, {} ); // $ExpectError - typedarraypool.malloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided an incorrect number of arguments... -{ - typedarraypool.malloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `calloc` method which returns a typed array or null... -{ - typedarraypool.calloc(); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `calloc` method is provided a first argument which is not a number... -{ - typedarraypool.calloc( 'abc' ); // $ExpectError - typedarraypool.calloc( true ); // $ExpectError - typedarraypool.calloc( false ); // $ExpectError - typedarraypool.calloc( null ); // $ExpectError - typedarraypool.calloc( {} ); // $ExpectError - typedarraypool.calloc( [] ); // $ExpectError - typedarraypool.calloc( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.calloc( 4, true ); // $ExpectError - typedarraypool.calloc( 4, false ); // $ExpectError - typedarraypool.calloc( 4, null ); // $ExpectError - typedarraypool.calloc( 4, 'abc' ); // $ExpectError - typedarraypool.calloc( 4, 123 ); // $ExpectError - typedarraypool.calloc( 4, [] ); // $ExpectError - typedarraypool.calloc( 4, {} ); // $ExpectError - typedarraypool.calloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided an incorrect number of arguments... -{ - typedarraypool.calloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `factory` method which returns a typed array pool.. -{ - typedarraypool.factory(); // $ExpectType Pool - typedarraypool.factory( { 'highWaterMark': 556 } ); // $ExpectType Pool -} - -// The compiler throws an error if the `factory` method is provided a `highWaterMark` option which is not a number... -{ - typedarraypool.factory( { 'highWaterMark': true } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': false } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': 'abc' } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': null } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': [] } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': {} } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an incorrect number of arguments... -{ - typedarraypool.factory( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` method which returns void... -{ - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.free( arr ); // $ExpectType void -} - -// The compiler throws an error if the `free` method is provided a first argument which is neither a typed array nor array buffer... -{ - typedarraypool.free( true ); // $ExpectError - typedarraypool.free( false ); // $ExpectError - typedarraypool.free( 123 ); // $ExpectError - typedarraypool.free( 'abc' ); // $ExpectError - typedarraypool.free( null ); // $ExpectError - typedarraypool.free( {} ); // $ExpectError - typedarraypool.free( ( x: number ): number => x ); // $ExpectError -} - -// Attached to the main export is a `clear` method which returns void... -{ - typedarraypool.clear(); // $ExpectType void -} - -// The compiler throws an error if the `clear` method is provided arguments... -{ - typedarraypool.clear( {} ); // $ExpectError - typedarraypool.clear( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `highWaterMark` property... -{ - typedarraypool.highWaterMark; // $ExpectType number -} - -// Attached to the main export is a `nbytes` property... -{ - typedarraypool.nbytes; // $ExpectType number -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 24a7846..0000000 --- a/examples/index.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 randu = require( '@stdlib/random-base-randu' ); -var typedarraypool = require( './../lib' ); - -// Create a typed array pool which can allocate at most 1GB: -var typedarray = typedarraypool.factory({ - 'highWaterMark': 1e9 -}); - -// Inspect the pool: -console.log( 'Max bytes: %d', typedarray.highWaterMark ); -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Allocate an array for storing double-precision floating-point numbers: -var arr1 = typedarray( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Fill the array... -var i; -for ( i = 0; i < arr1.length; i++ ) { - arr1[ i ] = randu(); -} - -// Inspect array contents: -console.log( arr1 ); - -// Free the array: -typedarray.free( arr1 ); - -// Allocate another array similar to the previous one: -var arr2 = typedarray( 5, 'float64' ); -// returns - -// Check that we have been returned a new typed array view: -console.log( arr2 === arr1 ); -// => false - -// Inspect array contents: -console.log( arr2 ); - -// Free the array: -typedarray.free( arr2 ); - -// Allocate an initialized array: -var arr3 = typedarray.calloc( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect array contents: -console.log( arr3 ); - -// Free the array: -typedarray.free( arr3 ); - -// Clear the pool: -typedarray.clear(); - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 4254ef5..0f5442f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike, RealOrComplexTypedArray, NumericDataType as DataType } from '@stdlib/types/array'; import ArrayBuffer = require( '@stdlib/array-buffer' ); diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..63431cd --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.2.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-setter@v0.2.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/array-defaults@v0.2.1-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.2.1-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.2.1-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.2.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.2.1-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";var M={float64:8,float32:4,int16:2,int32:4,int8:1,uint16:2,uint32:4,uint8:1,uint8c:1,complex64:8,complex128:16},W=j.get("dtypes.default"),E=d("complex64"),H=d("complex128");function T(e){return e instanceof E}function L(e){return e instanceof H}function P(j){var E,H,P,V;if(P={highWaterMark:9007199254740992},arguments.length&&(V=function(e,t){return w(t)?k(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(c("01H2t","highWaterMark",e.highWaterMark)):null:new TypeError(c("01H2V",t))}(P,j),V))throw V;return H=function(e){var t,r;for(t=[],r=0;r0){for(t=u(x(e.byteLength)),t=y(H.length-1,t),r=H[t],s=0;sP.highWaterMark?null:(t=new v(e),E+=e,t)}(b(t)*M[r]))?s:new e(s,0,t)}function q(){var e,i,n,l,j,v,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:W,null===(n=d(i)))throw new TypeError(c("01H2Y",i));if(e<=0)return new n(0);if(r(arguments[0]))return Y(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,o(l)?l=h(l,0):m(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=Y(n,u,i)))return j;if(L(j)||T(j))return j.set(l),j;for(g=p(l),v=f(j),b=0;b[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '01H2Y', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = resolveGetter( arr );\n\t\t\tset = resolveSetter( out );\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '01H2r', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( '01H2s', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'highWaterMark': 1024\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '01H2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'highWaterMark' ) ) {\n\t\topts.highWaterMark = options.highWaterMark;\n\t\tif ( !isNonNegativeInteger( opts.highWaterMark ) ) {\n\t\t\treturn new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Initializes a cache for pooled typed array buffers.\n*\n* @private\n* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size\n* @returns {ArrayArray} initialized cache\n*/\nfunction pool( n ) {\n\tvar out;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < n+1; i++ ) {\n\t\tout.push( [] );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default pool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DEFAULT_DTYPE","ARRAY_DEFAULTS","get","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","options","nbytes","pool","opts","err","highWaterMark","arguments","length","isObject","hasOwnProp","isNonNegativeInteger","TypeError","format","validate","n","out","i","push","createPool","ceil","log2","setReadOnly","malloc","nargs","tmp","reinterpret128","reinterpret64","buf","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","setReadOnlyAccessor","typedarray","ctor","len","dtype","pop","ArrayBuffer","arraybuffer","ceil2","BYTES_PER_ELEMENT","set","isString","isCollection","isComplex128Array","isComplex64Array","test","resolveGetter","resolveSetter","typedarraypool","main"],"mappings":";;q+EAoDIA,EAAgBC,EAAeC,IAAK,kBACpCC,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,ECjFO,CACNE,cAAiB,kBDiFbC,UAAUC,SACdH,EEnEF,SAAmBD,EAAMH,GACxB,OAAMQ,EAAUR,GAGXS,EAAYT,EAAS,mBACzBG,EAAKE,cAAgBL,EAAQK,eACvBK,EAAsBP,EAAKE,gBACzB,IAAIM,UAAWC,EAAQ,QAAS,gBAAiBT,EAAKE,gBAGxD,KARC,IAAIM,UAAWC,EAAQ,QAASZ,GASzC,CFwDQa,CAAUV,EAAMH,GACjBI,GACJ,MAAMA,EAaR,OAVAF,EG5FD,SAAeY,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,CHmFQG,CAAYC,EAAMC,EAAMjB,EAAKE,iBACpCJ,EAAS,EAEToB,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,UA+JrB,WACC,IAAIC,EACAR,EACAS,EACAR,EAEJO,EAAQjB,UAAUC,OAEjBQ,EADc,IAAVQ,EACED,IACe,IAAVC,EACLD,EAAQhB,UAAW,IAEnBgB,EAAQhB,UAAW,GAAKA,UAAW,IAE1C,GAAa,OAARS,EASJ,IANCS,EADI1B,EAAiBiB,GACfU,EAAgBV,EAAK,GAChBnB,EAAgBmB,GACrBW,EAAeX,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAIQ,EAAIjB,OAAQS,IAC5BQ,EAAKR,GAAM,EAGb,OAAOD,CACP,IA1LDM,EAAaC,EAAQ,QAwMrB,SAAeK,GACd,IAAIb,EACAc,EACAZ,EACJ,GAAKa,EAAkBF,IAASA,EAAIG,OACnCH,EAAMA,EAAIG,YACJ,IAAMC,EAAeJ,GAC3B,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAEvC,GAAKA,EAAIK,WAAa,EAAI,CAQzB,IAPAlB,EAAImB,EAAOb,EAAMO,EAAIK,aAGrBlB,EAAIoB,EAAKhC,EAAKK,OAAO,EAAGO,GAGxBc,EAAI1B,EAAMY,GACJE,EAAI,EAAGA,EAAIY,EAAErB,OAAQS,IAC1B,GAAKY,EAAGZ,KAAQW,EACf,OAAO,EAITC,EAAEX,KAAMU,EACR,CACD,OAAO,CACP,IAjODN,EAAaC,EAAQ,SAwOrB,WACC,IAAIN,EACJ,IAAMA,EAAI,EAAGA,EAAId,EAAKK,OAAQS,IAC7Bd,EAAMc,GAAIT,OAAS,EAEpBN,EAAS,CACT,IA7ODoB,EAAaC,EAAQ,gBAAiBnB,EAAKE,eAC3C8B,EAAqBb,EAAQ,UAU7B,WACC,OAAOrB,CACP,IAVMqB,EAmDP,SAASc,EAAYC,EAAMC,EAAKC,GAC/B,IAAIZ,EACJ,OAAa,IAARW,EACG,IAAID,EAAM,GAGL,QADbV,EArCD,SAAsBb,GACrB,IAAIa,EACAX,EAMJ,OAHAA,EAAII,EAAMN,IAGDZ,EAAKK,QAAUL,EAAMc,GAAIT,OAC1BL,EAAMc,GAAIwB,MAGbvC,EAAOa,EAAIX,EAAKE,cACb,MAERsB,EAAM,IAAIc,EAAa3B,GAGvBb,GAAUa,EAEHa,EACP,CAgBMe,CAAaC,EAAOL,GAAMM,EAAmBL,KAE3CZ,EAED,IAAIU,EAAMV,EAAK,EAAGW,EACzB,CAkBD,SAAShB,IACR,IAAIC,EACAgB,EACAF,EACAxC,EACAkB,EACA8B,EACArD,EACA8C,EACAtB,EAUJ,GALCuB,GAHDhB,EAAQjB,UAAUC,SACJuC,EAAUxC,UAAWiB,EAAM,IAEhCjB,UADRiB,GAAS,GAGDjC,EAGK,QADd+C,EAAO3C,EAAO6C,IAEb,MAAM,IAAI5B,UAAWC,EAAQ,QAAS2B,IAEvC,GAAKhB,GAAS,EACb,OAAO,IAAIc,EAAM,GAGlB,GAAK3B,EAAsBJ,UAAW,IACrC,OAAO8B,EAAYC,EAAM/B,UAAW,GAAKiC,GAG1C,GAAKQ,EAAczC,UAAW,IAAQ,CAYrC,GAVAgC,GADAzC,EAAMS,UAAW,IACPC,OACLyC,EAAmBnD,GACvBA,EAAM4B,EAAgB5B,EAAK,GAChBoD,EAAkBpD,GAC7BA,EAAM6B,EAAe7B,EAAK,GACf,WAAWqD,KAAMX,KAE5BD,GAAO,GAGK,QADbvB,EAAMqB,EAAYC,EAAMC,EAAKC,IAE5B,OAAOxB,EAER,GAAKjB,EAAiBiB,IAASnB,EAAgBmB,GAE9C,OADAA,EAAI8B,IAAKhD,GACFkB,EAKR,IAFAvB,EAAM2D,EAAetD,GACrBgD,EAAMO,EAAerC,GACfC,EAAI,EAAGA,EAAIsB,EAAKtB,IACrB6B,EAAK9B,EAAKC,EAAGxB,EAAKK,EAAKmB,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,QAASN,UAAW,IACjD,CAkGF,CIrTG,IAAC+C,EAAiBtD,ICPrBsB,EAAAiC,EAAA,UAAAvD"} \ No newline at end of file diff --git a/lib/bytes_per_element.json b/lib/bytes_per_element.json deleted file mode 100644 index f97fe70..0000000 --- a/lib/bytes_per_element.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "float64": 8, - "float32": 4, - "int16": 2, - "int32": 4, - "int8": 1, - "uint16": 2, - "uint32": 4, - "uint8": 1, - "uint8c": 1, - "complex64": 8, - "complex128": 16 -} diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index a421711..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +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'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'highWaterMark': 9007199254740992 - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 3fe17ca..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,372 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var isComplex64Array = require( '@stdlib/assert-is-complex64array' ); -var isComplex128Array = require( '@stdlib/assert-is-complex128array' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var ctors = require( '@stdlib/array-typed-ctors' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var resolveSetter = require( '@stdlib/array-base-resolve-setter' ); -var ARRAY_DEFAULTS = require( '@stdlib/array-defaults' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil = require( '@stdlib/math-base-special-ceil' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); -var log2 = require( '@stdlib/math-base-special-log2' ); -var min = require( '@stdlib/math-base-special-min' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var createPool = require( './pool.js' ); -var BYTES_PER_ELEMENT = require( './bytes_per_element.json' ); - - -// VARIABLES // - -var DEFAULT_DTYPE = ARRAY_DEFAULTS.get( 'dtypes.default' ); -var Complex64Array = ctors( 'complex64' ); -var Complex128Array = ctors( 'complex128' ); - - -// FUNCTIONS // - -/** -* Tests whether an array is a single-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a single-precision complex floating-point number array -*/ -function isCmplx64Array( arr ) { - return ( arr instanceof Complex64Array ); -} - -/** -* Tests whether an array is a double-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a double-precision complex floating-point number array -*/ -function isCmplx128Array( arr ) { - return ( arr instanceof Complex128Array ); -} - - -// MAIN // - -/** -* Creates a typed array pool. -* -* @param {Options} [options] - pool options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} allocator -* -* @example -* var typedarraypool = factory(); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -function factory( options ) { - var nbytes; - var pool; - var opts; - var err; - - opts = defaults(); - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - pool = createPool( ceil( log2( opts.highWaterMark ) ) ); - nbytes = 0; - - setReadOnly( malloc, 'malloc', malloc ); // circular reference - setReadOnly( malloc, 'calloc', calloc ); - setReadOnly( malloc, 'free', free ); - setReadOnly( malloc, 'clear', clear ); - setReadOnly( malloc, 'highWaterMark', opts.highWaterMark ); - setReadOnlyAccessor( malloc, 'nbytes', getBytes ); - - return malloc; - - /** - * Returns the number of allocated bytes. - * - * @private - * @returns {NonNegativeInteger} number of allocated bytes - */ - function getBytes() { - return nbytes; - } - - /** - * Returns an array buffer. - * - * @private - * @param {NonNegativeInteger} n - number of bytes - * @returns {(ArrayBuffer|null)} array buffer or null - */ - function arraybuffer( n ) { - var buf; - var i; - - // Convert the number of bytes to an index in our pool table: - i = log2( n ); - - // If we already have an available array buffer, use it... - if ( i < pool.length && pool[ i ].length ) { - return pool[ i ].pop(); - } - // Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate... - if ( nbytes+n > opts.highWaterMark ) { - return null; - } - buf = new ArrayBuffer( n ); - - // Update the running counter of allocated bytes: - nbytes += n; - - return buf; - } - - /** - * Returns a typed array. - * - * @private - * @param {Function} ctor - typed array constructor - * @param {NonNegativeInteger} len - view length - * @param {string} dtype - data type - * @returns {(TypedArray|null)} typed array or null - */ - function typedarray( ctor, len, dtype ) { - var buf; - if ( len === 0 ) { - return new ctor( 0 ); - } - buf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] ); - if ( buf === null ) { - return buf; - } - return new ctor( buf, 0, len ); - } - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length or an array-like object - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function malloc() { - var nargs; - var dtype; - var ctor; - var arr; - var out; - var set; - var get; - var len; - var i; - - nargs = arguments.length; - if ( nargs && isString( arguments[ nargs-1 ] ) ) { - nargs -= 1; - dtype = arguments[ nargs ]; - } else { - dtype = DEFAULT_DTYPE; - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( '01H2Y', dtype ) ); - } - if ( nargs <= 0 ) { - return new ctor( 0 ); - } - // Check if provided a typed array length... - if ( isNonNegativeInteger( arguments[ 0 ] ) ) { - return typedarray( ctor, arguments[ 0 ], dtype ); - } - // Check if provided an array-like object containing data elements... - if ( isCollection( arguments[ 0 ] ) ) { - arr = arguments[ 0 ]; - len = arr.length; - if ( isComplex128Array( arr ) ) { - arr = reinterpret128( arr, 0 ); - } else if ( isComplex64Array( arr ) ) { - arr = reinterpret64( arr, 0 ); - } else if ( /^complex/.test( dtype ) ) { - // Assume we've been provided an array of interleaved real and imaginary components... - len /= 2; - } - out = typedarray( ctor, len, dtype ); - if ( out === null ) { - return out; - } - if ( isCmplx128Array( out ) || isCmplx64Array( out ) ) { - out.set( arr ); - return out; - } - // Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other "unsafe" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things... - get = resolveGetter( arr ); - set = resolveSetter( out ); - for ( i = 0; i < len; i++ ) { - set( out, i, get( arr, i ) ); - } - return out; - } - throw new TypeError( format( '01H2r', arguments[ 0 ] ) ); - } - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {NonNegativeInteger} [len=0] - array length - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function calloc() { - var nargs; - var out; - var tmp; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - out = malloc(); - } else if ( nargs === 1 ) { - out = malloc( arguments[ 0 ] ); - } else { - out = malloc( arguments[ 0 ], arguments[ 1 ] ); - } - if ( out !== null ) { - // Initialize the memory... - if ( isCmplx128Array( out ) ) { - tmp = reinterpret128( out, 0 ); - } else if ( isCmplx64Array( out ) ) { - tmp = reinterpret64( out, 0 ); - } else { - tmp = out; - } - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = 0.0; - } - } - return out; - } - - /** - * Frees a typed array or typed array buffer. - * - * ## Notes - * - * - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., "freeing" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool. - * - * @private - * @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free - * @throws {TypeError} must provide a typed array or typed array buffer - * @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed - */ - function free( buf ) { - var n; - var p; - var i; - if ( isTypedArrayLike( buf ) && buf.buffer ) { - buf = buf.buffer; - } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( '01H2s', buf ) ); - } - if ( buf.byteLength > 0 ) { - n = floor( log2( buf.byteLength ) ); - - // Prohibit "freeing" array buffers which would potentially allow users to circumvent high water mark limits: - n = min( pool.length-1, n ); - - // Ensure that we do not attempt to free the same buffer more than once... - p = pool[ n ]; - for ( i = 0; i < p.length; i++ ) { - if ( p[ i ] === buf ) { - return false; - } - } - // Add the buffer to our pool of free buffers: - p.push( buf ); - } - return true; - } - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @private - */ - function clear() { - var i; - for ( i = 0; i < pool.length; i++ ) { - pool[ i ].length = 0; - } - nbytes = 0; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6c12a4e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Typed array pool. -* -* @module @stdlib/array-pool -* -* @example -* var typedarraypool = require( '@stdlib/array-pool' ); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8f69ee3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,63 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @name typedarraypool -* @type {Function} -* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a valid array length or an array-like object -* @throws {TypeError} must provide a recognized data type -* @returns {(TypedArray|null)} typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -var typedarraypool = factory(); - - -// EXPORTS // - -module.exports = typedarraypool; diff --git a/lib/pool.js b/lib/pool.js deleted file mode 100644 index 5abd287..0000000 --- a/lib/pool.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Initializes a cache for pooled typed array buffers. -* -* @private -* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size -* @returns {ArrayArray} initialized cache -*/ -function pool( n ) { - var out; - var i; - - out = []; - for ( i = 0; i < n+1; i++ ) { - out.push( [] ); - } - return out; -} - - -// EXPORTS // - -module.exports = pool; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index da746bb..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'highWaterMark': 1024 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '01H2V', options ) ); - } - if ( hasOwnProp( options, 'highWaterMark' ) ) { - opts.highWaterMark = options.highWaterMark; - if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 050b270..ce31461 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Typed array pool.", "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,78 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-resolve-getter": "^0.2.0", - "@stdlib/array-base-resolve-setter": "^0.2.1", - "@stdlib/array-buffer": "^0.2.1", - "@stdlib/array-defaults": "^0.2.1", - "@stdlib/array-typed-ctors": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-arraybuffer": "^0.2.1", - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-complex128array": "^0.2.1", - "@stdlib/assert-is-complex64array": "^0.2.1", - "@stdlib/assert-is-nonnegative-integer": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/assert-is-string": "^0.2.1", - "@stdlib/assert-is-typed-array-like": "^0.2.1", - "@stdlib/math-base-special-ceil": "^0.2.1", - "@stdlib/math-base-special-ceil2": "^0.2.1", - "@stdlib/math-base-special-floor": "^0.2.1", - "@stdlib/math-base-special-log2": "^0.2.1", - "@stdlib/math-base-special-min": "^0.2.1", - "@stdlib/strided-base-reinterpret-complex128": "^0.2.1", - "@stdlib/strided-base-reinterpret-complex64": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.2.0", - "@stdlib/array-complex64": "^0.2.0", - "@stdlib/array-float32": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/array-int16": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/array-int8": "^0.2.1", - "@stdlib/array-uint16": "^0.2.1", - "@stdlib/array-uint32": "^0.2.1", - "@stdlib/array-uint8": "^0.2.1", - "@stdlib/array-uint8c": "^0.2.1", - "@stdlib/assert-instance-of": "^0.2.1", - "@stdlib/assert-is-complex-typed-array": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-typed-array": "^0.2.1", - "@stdlib/complex-float32": "^0.2.1", - "@stdlib/complex-float64": "^0.2.1", - "@stdlib/complex-imag": "^0.2.1", - "@stdlib/complex-imagf": "^0.2.1", - "@stdlib/complex-real": "^0.2.1", - "@stdlib/complex-realf": "^0.2.1", - "@stdlib/math-base-special-pow": "^0.2.1", - "@stdlib/random-base-randu": "^0.2.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..dea0590 --- /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.factory.js b/test/test.factory.js deleted file mode 100644 index 396aee2..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,2240 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function (no options)', function test( t ) { - t.strictEqual( typeof factory(), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - t.strictEqual( typeof factory( {} ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided a `highWaterMark` option which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (length)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a function which returns a typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, length)', function test( t ) { - var typedarraypool = factory(); - var arr; - - arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a `malloc` method which is a circular reference', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - var buf; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the returned function is a property which returns the pool\'s high water mark', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function supports specifying a high water mark which limits the total amount of memory a pool can allocate', function test( t ) { - var typedarraypool; - var arr1; - var arr2; - - typedarraypool = factory({ - 'highWaterMark': 64 // bytes - }); - - typedarraypool.clear(); - - arr1 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr1.length, 8, 'returns expected value' ); - t.strictEqual( arr1.byteLength, 64, 'returns expected value' ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - typedarraypool.free( arr1 ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Create an array which is less than or equal to the high water mark: - arr2 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr2.length, 8, 'returns expected value' ); - t.strictEqual( arr2.byteLength, 64, 'returns expected value' ); - - typedarraypool.free( arr2 ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a property which returns the total number of accumulated bytes', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var typedarraypool; - var arrs; - var i; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 54aa5ee..0000000 --- a/test/test.js +++ /dev/null @@ -1,1797 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var typedarraypool = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -}); From 61f21286a415cfd620c0c761bb9fd88e702a3351 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 21:31:28 +0000 Subject: [PATCH 075/103] Update README.md for ESM bundle v0.2.1 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1fb7dd3..4abf153 100644 --- a/README.md +++ b/README.md @@ -52,13 +52,13 @@ limitations under the License. ## Usage ```javascript -import typedarraypool from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-pool@esm/index.mjs'; +import typedarraypool from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-pool@v0.2.1-esm/index.mjs'; ``` You can also import the following named exports from the package: ```javascript -import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-pool@esm/index.mjs'; +import { factory } from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-pool@v0.2.1-esm/index.mjs'; ``` #### typedarraypool( \[dtype] ) @@ -392,7 +392,7 @@ pool.free( arr ); - - - - From e498efa0704839eb739b7ddda4008ca38a8c7ac6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 13:51:57 +0000 Subject: [PATCH 079/103] 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 | 45 +- SECURITY.md | 5 - benchmark/benchmark.calloc.js | 246 -- benchmark/benchmark.factory.js | 71 - benchmark/benchmark.js | 246 -- benchmark/benchmark.length.complex128.js | 102 - benchmark/benchmark.length.complex64.js | 102 - benchmark/benchmark.length.float32.js | 102 - benchmark/benchmark.length.float64.js | 102 - benchmark/benchmark.length.int16.js | 102 - benchmark/benchmark.length.int32.js | 102 - benchmark/benchmark.length.int8.js | 102 - benchmark/benchmark.length.uint16.js | 102 - benchmark/benchmark.length.uint32.js | 102 - benchmark/benchmark.length.uint8.js | 102 - benchmark/benchmark.length.uint8c.js | 102 - benchmark/benchmark.malloc.js | 246 -- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 347 -- docs/types/test.ts | 193 - examples/index.js | 80 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/bytes_per_element.json | 13 - lib/defaults.js | 42 - lib/factory.js | 372 -- lib/index.js | 56 - lib/main.js | 63 - lib/pool.js | 44 - lib/validate.js | 66 - package.json | 99 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 2240 ---------- test/test.js | 1797 -------- 63 files changed, 4871 insertions(+), 10647 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.calloc.js delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.complex128.js delete mode 100644 benchmark/benchmark.length.complex64.js delete mode 100644 benchmark/benchmark.length.float32.js delete mode 100644 benchmark/benchmark.length.float64.js delete mode 100644 benchmark/benchmark.length.int16.js delete mode 100644 benchmark/benchmark.length.int32.js delete mode 100644 benchmark/benchmark.length.int8.js delete mode 100644 benchmark/benchmark.length.uint16.js delete mode 100644 benchmark/benchmark.length.uint32.js delete mode 100644 benchmark/benchmark.length.uint8.js delete mode 100644 benchmark/benchmark.length.uint8c.js delete mode 100644 benchmark/benchmark.malloc.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/bytes_per_element.json delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/pool.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 852bb1a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T05:55:08.122Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ea35f20..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/array/pool) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6f7c875..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/array/pool) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 869c4e9..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -495,7 +492,7 @@ console.log( 'nbytes: %d', typedarray.nbytes ); ## 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]. @@ -564,7 +561,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/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.calloc.js b/benchmark/benchmark.calloc.js deleted file mode 100644 index fd8f53d..0000000 --- a/benchmark/benchmark.calloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':calloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 58918bb..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = typedarray.factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:highWaterMark', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'highWaterMark': 0 - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.highWaterMark = i; - f = typedarray.factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 4310559..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.complex128.js b/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 12c6668..0000000 --- a/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex64.js b/benchmark/benchmark.length.complex64.js deleted file mode 100644 index ca2b45c..0000000 --- a/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float32.js b/benchmark/benchmark.length.float32.js deleted file mode 100644 index b3b4508..0000000 --- a/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float64.js b/benchmark/benchmark.length.float64.js deleted file mode 100644 index 5f0132d..0000000 --- a/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int16.js b/benchmark/benchmark.length.int16.js deleted file mode 100644 index 9f253cb..0000000 --- a/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int32.js b/benchmark/benchmark.length.int32.js deleted file mode 100644 index f83e795..0000000 --- a/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int8.js b/benchmark/benchmark.length.int8.js deleted file mode 100644 index 5b01174..0000000 --- a/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint16.js b/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 32b0a5d..0000000 --- a/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint32.js b/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 290b90c..0000000 --- a/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8.js b/benchmark/benchmark.length.uint8.js deleted file mode 100644 index ff7d733..0000000 --- a/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8c.js b/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index 8f0d10a..0000000 --- a/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.malloc.js b/benchmark/benchmark.malloc.js deleted file mode 100644 index 1661907..0000000 --- a/benchmark/benchmark.malloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':malloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 612de17..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/array/pool" -%% click B href "https://github.com/stdlib-js/array-pool/tree/main" -%% click C href "https://github.com/stdlib-js/array-pool/tree/production" -%% click D href "https://github.com/stdlib-js/array-pool/tree/esm" -%% click E href "https://github.com/stdlib-js/array-pool/tree/deno" -%% click F href "https://github.com/stdlib-js/array-pool/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/pool -[production-url]: https://github.com/stdlib-js/array-pool/tree/production -[deno-url]: https://github.com/stdlib-js/array-pool/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-pool/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-pool/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-pool/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-pool/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-pool/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 5160b6f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import typedarraypool from '../docs/types/index'; -export = typedarraypool; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4f5b474..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var l=function(n,i){return function(){return i||n((i={exports:{}}).exports,i),i.exports}};var M=l(function(Er,w){ -function I(){return{highWaterMark:9007199254740992}}w.exports=I -});var T=l(function(Tr,E){ -var U=require('@stdlib/assert-is-plain-object/dist'),z=require('@stdlib/assert-has-own-property/dist'),G=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,k=require('@stdlib/error-tools-fmtprodmsg/dist');function H(n,i){return U(i)?z(i,"highWaterMark")&&(n.highWaterMark=i.highWaterMark,!G(n.highWaterMark))?new TypeError(k('01H2t',"highWaterMark",n.highWaterMark)):null:new TypeError(k('01H2V',i));}E.exports=H -});var C=l(function(Wr,W){ -function J(n){var i,u;for(i=[],u=0;uv.highWaterMark?null:(e=new or(r),i+=r,e)}function d(r,e,a){var t;return e===0?new r(0):(t=j(vr(e)*mr[a]),t===null?t:new r(t,0,e))}function o(){var r,e,a,t,s,x,A,c,f;if(r=arguments.length,r&&Q(arguments[r-1])?(r-=1,e=arguments[r]):e=pr,a=y(e),a===null)throw new TypeError(m('01H2Y',e));if(r<=0)return new a(0);if(X(arguments[0]))return d(a,arguments[0],e);if(Z(arguments[0])){if(t=arguments[0],c=t.length,tr(t)?t=b(t,0):er(t)?t=P(t,0):/^complex/.test(e)&&(c/=2),s=d(a,c,e),s===null)return s;if(R(s)||L(s))return s.set(t),s;for(A=ir(t),x=nr(s),f=0;f0){for(e=lr(p(r.byteLength)),e=fr(u.length-1,e),a=u[e],t=0;t[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = resolveGetter( arr );\n\t\t\tset = resolveSetter( out );\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nmodule.exports = typedarraypool;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* var typedarraypool = require( '@stdlib/array-pool' );\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,cAAiB,gBAClB,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,eAAgB,IACzCD,EAAK,cAAgBC,EAAQ,cACxB,CAACJ,EAAsBG,EAAK,aAAc,GACvC,IAAI,UAAWF,EAAQ,2EAA4E,gBAAiBE,EAAK,aAAc,CAAE,EAG3I,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cA6BA,SAASC,EAAM,EAAI,CAClB,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAI,EAAE,EAAGA,IACrBD,EAAI,KAAM,CAAC,CAAE,EAEd,OAAOA,CACR,CAKAF,EAAO,QAAUC,IC3CjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,QAAW,EACX,QAAW,EACX,MAAS,EACT,MAAS,EACT,KAAQ,EACR,OAAU,EACV,OAAU,EACV,MAAS,EACT,OAAU,EACT,UAAa,EACb,WAAc,EAChB,ICZA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAe,QAAS,8BAA+B,EACvDC,EAAmB,QAAS,oCAAqC,EACjEC,GAAgB,QAAS,+BAAgC,EACzDC,GAAmB,QAAS,kCAAmC,EAC/DC,GAAoB,QAAS,mCAAoC,EACjEC,EAAc,QAAS,uDAAwD,EAC/EC,GAAsB,QAAS,uDAAwD,EACvFC,EAAQ,QAAS,2BAA4B,EAC7CC,EAAgB,QAAS,4CAA6C,EACtEC,EAAiB,QAAS,6CAA8C,EACxEC,GAAgB,QAAS,mCAAoC,EAC7DC,GAAgB,QAAS,mCAAoC,EAC7DC,GAAiB,QAAS,wBAAyB,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,GAAc,QAAS,sBAAuB,EAC9CC,GAAO,QAAS,gCAAiC,EACjDC,GAAQ,QAAS,iCAAkC,EACnDC,GAAQ,QAAS,iCAAkC,EACnDC,EAAO,QAAS,gCAAiC,EACjDC,GAAM,QAAS,+BAAgC,EAC/CC,GAAW,IACXC,GAAW,IACXC,GAAa,IACbC,GAAoB,IAKpBC,GAAgBZ,GAAe,IAAK,gBAAiB,EACrDa,GAAiBlB,EAAO,WAAY,EACpCmB,GAAkBnB,EAAO,YAAa,EAY1C,SAASoB,EAAgBC,EAAM,CAC9B,OAASA,aAAeH,EACzB,CASA,SAASI,EAAiBD,EAAM,CAC/B,OAASA,aAAeF,EACzB,CA6BA,SAASI,GAASC,EAAU,CAC3B,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,EAAOd,GAAS,EACX,UAAU,SACde,EAAMd,GAAUa,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAAF,EAAOX,GAAYP,GAAMG,EAAMgB,EAAK,aAAc,CAAE,CAAE,EACtDF,EAAS,EAET3B,EAAa+B,EAAQ,SAAUA,CAAO,EACtC/B,EAAa+B,EAAQ,SAAUC,CAAO,EACtChC,EAAa+B,EAAQ,OAAQE,CAAK,EAClCjC,EAAa+B,EAAQ,QAASG,CAAM,EACpClC,EAAa+B,EAAQ,gBAAiBF,EAAK,aAAc,EACzD5B,GAAqB8B,EAAQ,SAAUI,CAAS,EAEzCJ,EAQP,SAASI,GAAW,CACnB,OAAOR,CACR,CASA,SAASS,EAAaC,EAAI,CACzB,IAAIC,EACAC,EAMJ,OAHAA,EAAI1B,EAAMwB,CAAE,EAGPE,EAAIX,EAAK,QAAUA,EAAMW,CAAE,EAAE,OAC1BX,EAAMW,CAAE,EAAE,IAAI,EAGjBZ,EAAOU,EAAIR,EAAK,cACb,MAERS,EAAM,IAAI7B,GAAa4B,CAAE,EAGzBV,GAAUU,EAEHC,EACR,CAWA,SAASE,EAAYC,EAAMC,EAAKC,EAAQ,CACvC,IAAIL,EACJ,OAAKI,IAAQ,EACL,IAAID,EAAM,CAAE,GAEpBH,EAAMF,EAAaxB,GAAO8B,CAAI,EAAExB,GAAmByB,CAAM,CAAE,EACtDL,IAAQ,KACLA,EAED,IAAIG,EAAMH,EAAK,EAAGI,CAAI,EAC9B,CAkBA,SAASX,GAAS,CACjB,IAAIa,EACAD,EACAF,EACAlB,EACAsB,EACAC,EACAC,EACAL,EACAH,EAUJ,GARAK,EAAQ,UAAU,OACbA,GAASnD,EAAU,UAAWmD,EAAM,CAAE,CAAE,GAC5CA,GAAS,EACTD,EAAQ,UAAWC,CAAM,GAEzBD,EAAQxB,GAETsB,EAAOvC,EAAOyC,CAAM,EACfF,IAAS,KACb,MAAM,IAAI,UAAWjC,EAAQ,sEAAuEmC,CAAM,CAAE,EAE7G,GAAKC,GAAS,EACb,OAAO,IAAIH,EAAM,CAAE,EAGpB,GAAK/C,EAAsB,UAAW,CAAE,CAAE,EACzC,OAAO8C,EAAYC,EAAM,UAAW,CAAE,EAAGE,CAAM,EAGhD,GAAKhD,EAAc,UAAW,CAAE,CAAE,EAAI,CAYrC,GAXA4B,EAAM,UAAW,CAAE,EACnBmB,EAAMnB,EAAI,OACLxB,GAAmBwB,CAAI,EAC3BA,EAAMnB,EAAgBmB,EAAK,CAAE,EAClBzB,GAAkByB,CAAI,EACjCA,EAAMpB,EAAeoB,EAAK,CAAE,EACjB,WAAW,KAAMoB,CAAM,IAElCD,GAAO,GAERG,EAAML,EAAYC,EAAMC,EAAKC,CAAM,EAC9BE,IAAQ,KACZ,OAAOA,EAER,GAAKrB,EAAiBqB,CAAI,GAAKvB,EAAgBuB,CAAI,EAClD,OAAAA,EAAI,IAAKtB,CAAI,EACNsB,EAKR,IAFAE,EAAM1C,GAAekB,CAAI,EACzBuB,EAAMxC,GAAeuC,CAAI,EACnBN,EAAI,EAAGA,EAAIG,EAAKH,IACrBO,EAAKD,EAAKN,EAAGQ,EAAKxB,EAAKgB,CAAE,CAAE,EAE5B,OAAOM,CACR,CACA,MAAM,IAAI,UAAWrC,EAAQ,wGAAyG,UAAW,CAAE,CAAE,CAAE,CACxJ,CAgBA,SAASwB,GAAS,CACjB,IAAIY,EACAC,EACAG,EACAT,EAUJ,GARAK,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAMd,EAAO,EACFa,IAAU,EACrBC,EAAMd,EAAQ,UAAW,CAAE,CAAE,EAE7Bc,EAAMd,EAAQ,UAAW,CAAE,EAAG,UAAW,CAAE,CAAE,EAEzCc,IAAQ,KASZ,IAPKrB,EAAiBqB,CAAI,EACzBG,EAAM5C,EAAgByC,EAAK,CAAE,EAClBvB,EAAgBuB,CAAI,EAC/BG,EAAM7C,EAAe0C,EAAK,CAAE,EAE5BG,EAAMH,EAEDN,EAAI,EAAGA,EAAIS,EAAI,OAAQT,IAC5BS,EAAKT,CAAE,EAAI,EAGb,OAAOM,CACR,CAcA,SAASZ,EAAMK,EAAM,CACpB,IAAID,EACAY,EACAV,EACJ,GAAK3C,EAAkB0C,CAAI,GAAKA,EAAI,OACnCA,EAAMA,EAAI,eACC,CAACzC,GAAeyC,CAAI,EAC/B,MAAM,IAAI,UAAW9B,EAAQ,4EAA6E8B,CAAI,CAAE,EAEjH,GAAKA,EAAI,WAAa,EAAI,CAQzB,IAPAD,EAAI1B,GAAOE,EAAMyB,EAAI,UAAW,CAAE,EAGlCD,EAAIvB,GAAKc,EAAK,OAAO,EAAGS,CAAE,EAG1BY,EAAIrB,EAAMS,CAAE,EACNE,EAAI,EAAGA,EAAIU,EAAE,OAAQV,IAC1B,GAAKU,EAAGV,CAAE,IAAMD,EACf,MAAO,GAITW,EAAE,KAAMX,CAAI,CACb,CACA,MAAO,EACR,CAOA,SAASJ,GAAQ,CAChB,IAAIK,EACJ,IAAMA,EAAI,EAAGA,EAAIX,EAAK,OAAQW,IAC7BX,EAAMW,CAAE,EAAE,OAAS,EAEpBZ,EAAS,CACV,CACD,CAKAnC,EAAO,QAAUiC,KCnXjB,IAAAyB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAU,IAmCVC,GAAiBD,GAAQ,EAK7BD,EAAO,QAAUE,KCnBjB,IAAIC,GAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,GAAU,IAKdF,GAAaC,EAAM,UAAWC,EAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isNonNegativeInteger", "format", "validate", "opts", "options", "require_pool", "__commonJSMin", "exports", "module", "pool", "out", "i", "require_bytes_per_element", "__commonJSMin", "exports", "module", "require_factory", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isCollection", "isTypedArrayLike", "isArrayBuffer", "isComplex64Array", "isComplex128Array", "setReadOnly", "setReadOnlyAccessor", "ctors", "reinterpret64", "reinterpret128", "resolveGetter", "resolveSetter", "ARRAY_DEFAULTS", "format", "ArrayBuffer", "ceil", "floor", "ceil2", "log2", "min", "defaults", "validate", "createPool", "BYTES_PER_ELEMENT", "DEFAULT_DTYPE", "Complex64Array", "Complex128Array", "isCmplx64Array", "arr", "isCmplx128Array", "factory", "options", "nbytes", "pool", "opts", "err", "malloc", "calloc", "free", "clear", "getBytes", "arraybuffer", "n", "buf", "i", "typedarray", "ctor", "len", "dtype", "nargs", "out", "set", "get", "tmp", "p", "require_main", "__commonJSMin", "exports", "module", "factory", "typedarraypool", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5244595..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,347 +0,0 @@ - -{{alias}}( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - Memory is **uninitialized**, which means that the contents of a returned - typed array may contain sensitive contents. - - The function supports the following data types: - - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - The default typed array data type is `float64`. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}() - [] - > arr = {{alias}}( 'float32' ) - [] - - -{{alias}}( length[, dtype] ) - Returns an uninitialized typed array having a specified length from a typed - array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > arr = {{alias}}( 5, 'int32' ) - - - -{{alias}}( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - This method shares the same security vulnerabilities mentioned above. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc() - - > arr = {{alias}}.malloc( 'float32' ) - - - -{{alias}}.malloc( length[, dtype] ) - Returns a typed array having a specified length from a typed array memory - pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc( 5 ) - - > arr = {{alias}}.malloc( 5, 'int32' ) - - - -{{alias}}.malloc( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}.malloc( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.calloc( [dtype] ) - Returns a zero-initialized typed array from a typed array memory pool. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc() - [] - > arr = {{alias}}.calloc( 'float32' ) - [] - - -{{alias}}.calloc( length[, dtype] ) - Returns a zero-initialized typed array having a specified length from a - typed array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}.calloc( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}.free( buf ) - Frees a typed array or typed array buffer for use in a future allocation. - - Parameters - ---------- - buf: TypedArray|ArrayBuffer - Typed array or typed array buffer to free. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ) - - -{{alias}}.clear() - Clears the typed array pool allowing garbage collection of previously - allocated (and currently free) array buffers. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - > {{alias}}.clear() - - -{{alias}}.highWaterMark - Read-only property returning the pool's high water mark. - - Once a high water mark is reached, typed array allocation fails. - - Examples - -------- - > {{alias}}.highWaterMark - - -{{alias}}.nbytes - Read-only property returning the total number of allocated bytes. - - The returned value is the total accumulated value. Hence, anytime a pool - must allocate a new array buffer (i.e., more memory), the pool increments - this value. - - The only time this value is decremented is when a pool is cleared. - - This behavior means that, while allocated buffers which are never freed may, - in fact, be garbage collected, they continue to count against the high water - mark limit. - - Accordingly, you should *always* free allocated buffers in order to prevent - the pool from believing that non-freed buffers are continually in use. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.nbytes - - -{{alias}}.factory( [options] ) - Creates a typed array pool. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.highWaterMark: integer (optional) - Maximum total memory (in bytes) which can be allocated. - - Returns - ------- - fcn: Function - Function for creating typed arrays from a typed array memory pool. - - Examples - -------- - > var pool = {{alias}}.factory(); - > var arr1 = pool( 3, 'float64' ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 4336c42..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,193 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-empty */ -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import typedarraypool = require( './index' ); - - -// TESTS // - -// The function returns a typed array or null... -{ - typedarraypool(); // $ExpectType TypedArrayOrNull - typedarraypool( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the function is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool( true ); // $ExpectError - typedarraypool( false ); // $ExpectError - typedarraypool( null ); // $ExpectError - typedarraypool( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized data type... -{ - typedarraypool( 4, true ); // $ExpectError - typedarraypool( 4, false ); // $ExpectError - typedarraypool( 4, null ); // $ExpectError - typedarraypool( 4, 'abc' ); // $ExpectError - typedarraypool( 4, 123 ); // $ExpectError - typedarraypool( 4, [] ); // $ExpectError - typedarraypool( 4, {} ); // $ExpectError - typedarraypool( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an incorrect number of arguments... -{ - typedarraypool( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `malloc` method which returns a typed array or null... -{ - typedarraypool.malloc(); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.malloc( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `malloc` method is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool.malloc( true ); // $ExpectError - typedarraypool.malloc( false ); // $ExpectError - typedarraypool.malloc( null ); // $ExpectError - typedarraypool.malloc( {} ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.malloc( 4, true ); // $ExpectError - typedarraypool.malloc( 4, false ); // $ExpectError - typedarraypool.malloc( 4, null ); // $ExpectError - typedarraypool.malloc( 4, 'abc' ); // $ExpectError - typedarraypool.malloc( 4, 123 ); // $ExpectError - typedarraypool.malloc( 4, [] ); // $ExpectError - typedarraypool.malloc( 4, {} ); // $ExpectError - typedarraypool.malloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided an incorrect number of arguments... -{ - typedarraypool.malloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `calloc` method which returns a typed array or null... -{ - typedarraypool.calloc(); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `calloc` method is provided a first argument which is not a number... -{ - typedarraypool.calloc( 'abc' ); // $ExpectError - typedarraypool.calloc( true ); // $ExpectError - typedarraypool.calloc( false ); // $ExpectError - typedarraypool.calloc( null ); // $ExpectError - typedarraypool.calloc( {} ); // $ExpectError - typedarraypool.calloc( [] ); // $ExpectError - typedarraypool.calloc( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.calloc( 4, true ); // $ExpectError - typedarraypool.calloc( 4, false ); // $ExpectError - typedarraypool.calloc( 4, null ); // $ExpectError - typedarraypool.calloc( 4, 'abc' ); // $ExpectError - typedarraypool.calloc( 4, 123 ); // $ExpectError - typedarraypool.calloc( 4, [] ); // $ExpectError - typedarraypool.calloc( 4, {} ); // $ExpectError - typedarraypool.calloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided an incorrect number of arguments... -{ - typedarraypool.calloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `factory` method which returns a typed array pool.. -{ - typedarraypool.factory(); // $ExpectType Pool - typedarraypool.factory( { 'highWaterMark': 556 } ); // $ExpectType Pool -} - -// The compiler throws an error if the `factory` method is provided a `highWaterMark` option which is not a number... -{ - typedarraypool.factory( { 'highWaterMark': true } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': false } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': 'abc' } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': null } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': [] } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': {} } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an incorrect number of arguments... -{ - typedarraypool.factory( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` method which returns void... -{ - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.free( arr ); // $ExpectType void -} - -// The compiler throws an error if the `free` method is provided a first argument which is neither a typed array nor array buffer... -{ - typedarraypool.free( true ); // $ExpectError - typedarraypool.free( false ); // $ExpectError - typedarraypool.free( 123 ); // $ExpectError - typedarraypool.free( 'abc' ); // $ExpectError - typedarraypool.free( null ); // $ExpectError - typedarraypool.free( {} ); // $ExpectError - typedarraypool.free( ( x: number ): number => x ); // $ExpectError -} - -// Attached to the main export is a `clear` method which returns void... -{ - typedarraypool.clear(); // $ExpectType void -} - -// The compiler throws an error if the `clear` method is provided arguments... -{ - typedarraypool.clear( {} ); // $ExpectError - typedarraypool.clear( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `highWaterMark` property... -{ - typedarraypool.highWaterMark; // $ExpectType number -} - -// Attached to the main export is a `nbytes` property... -{ - typedarraypool.nbytes; // $ExpectType number -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 24a7846..0000000 --- a/examples/index.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 randu = require( '@stdlib/random-base-randu' ); -var typedarraypool = require( './../lib' ); - -// Create a typed array pool which can allocate at most 1GB: -var typedarray = typedarraypool.factory({ - 'highWaterMark': 1e9 -}); - -// Inspect the pool: -console.log( 'Max bytes: %d', typedarray.highWaterMark ); -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Allocate an array for storing double-precision floating-point numbers: -var arr1 = typedarray( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Fill the array... -var i; -for ( i = 0; i < arr1.length; i++ ) { - arr1[ i ] = randu(); -} - -// Inspect array contents: -console.log( arr1 ); - -// Free the array: -typedarray.free( arr1 ); - -// Allocate another array similar to the previous one: -var arr2 = typedarray( 5, 'float64' ); -// returns - -// Check that we have been returned a new typed array view: -console.log( arr2 === arr1 ); -// => false - -// Inspect array contents: -console.log( arr2 ); - -// Free the array: -typedarray.free( arr2 ); - -// Allocate an initialized array: -var arr3 = typedarray.calloc( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect array contents: -console.log( arr3 ); - -// Free the array: -typedarray.free( arr3 ); - -// Clear the pool: -typedarray.clear(); - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 4254ef5..0f5442f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike, RealOrComplexTypedArray, NumericDataType as DataType } from '@stdlib/types/array'; import ArrayBuffer = require( '@stdlib/array-buffer' ); diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5787351 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.2.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-setter@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/array-defaults@v0.2.1-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.2.1-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.2.1-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.2.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.2.1-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";var M={float64:8,float32:4,int16:2,int32:4,int8:1,uint16:2,uint32:4,uint8:1,uint8c:1,complex64:8,complex128:16},W=j.get("dtypes.default"),E=d("complex64"),H=d("complex128");function T(e){return e instanceof E}function L(e){return e instanceof H}function P(j){var E,H,P,V;if(P={highWaterMark:9007199254740992},arguments.length&&(V=function(e,t){return w(t)?k(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(c("01H2t","highWaterMark",e.highWaterMark)):null:new TypeError(c("01H2V",t))}(P,j),V))throw V;return H=function(e){var t,r;for(t=[],r=0;r0){for(t=u(x(e.byteLength)),t=y(H.length-1,t),r=H[t],s=0;sP.highWaterMark?null:(t=new v(e),E+=e,t)}(b(t)*M[r]))?s:new e(s,0,t)}function q(){var e,i,n,l,j,v,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:W,null===(n=d(i)))throw new TypeError(c("01H2Y",i));if(e<=0)return new n(0);if(r(arguments[0]))return Y(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,o(l)?l=h(l,0):m(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=Y(n,u,i)))return j;if(L(j)||T(j))return j.set(l),j;for(g=p(l),v=f(j),b=0;b[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '01H2Y', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = resolveGetter( arr );\n\t\t\tset = resolveSetter( out );\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '01H2r', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( '01H2s', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'highWaterMark': 1024\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '01H2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'highWaterMark' ) ) {\n\t\topts.highWaterMark = options.highWaterMark;\n\t\tif ( !isNonNegativeInteger( opts.highWaterMark ) ) {\n\t\t\treturn new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Initializes a cache for pooled typed array buffers.\n*\n* @private\n* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size\n* @returns {ArrayArray} initialized cache\n*/\nfunction pool( n ) {\n\tvar out;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < n+1; i++ ) {\n\t\tout.push( [] );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default pool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DEFAULT_DTYPE","ARRAY_DEFAULTS","get","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","options","nbytes","pool","opts","err","highWaterMark","arguments","length","isObject","hasOwnProp","isNonNegativeInteger","TypeError","format","validate","n","out","i","push","createPool","ceil","log2","setReadOnly","malloc","nargs","tmp","reinterpret128","reinterpret64","buf","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","setReadOnlyAccessor","typedarray","ctor","len","dtype","pop","ArrayBuffer","arraybuffer","ceil2","BYTES_PER_ELEMENT","set","isString","isCollection","isComplex128Array","isComplex64Array","test","resolveGetter","resolveSetter","typedarraypool","main"],"mappings":";;q+EAoDIA,EAAgBC,EAAeC,IAAK,kBACpCC,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,ECjFO,CACNE,cAAiB,kBDiFbC,UAAUC,SACdH,EEnEF,SAAmBD,EAAMH,GACxB,OAAMQ,EAAUR,GAGXS,EAAYT,EAAS,mBACzBG,EAAKE,cAAgBL,EAAQK,eACvBK,EAAsBP,EAAKE,gBACzB,IAAIM,UAAWC,EAAQ,QAAS,gBAAiBT,EAAKE,gBAGxD,KARC,IAAIM,UAAWC,EAAQ,QAASZ,GASzC,CFwDQa,CAAUV,EAAMH,GACjBI,GACJ,MAAMA,EAaR,OAVAF,EG5FD,SAAeY,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,CHmFQG,CAAYC,EAAMC,EAAMjB,EAAKE,iBACpCJ,EAAS,EAEToB,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,UA+JrB,WACC,IAAIC,EACAR,EACAS,EACAR,EAEJO,EAAQjB,UAAUC,OAEjBQ,EADc,IAAVQ,EACED,IACe,IAAVC,EACLD,EAAQhB,UAAW,IAEnBgB,EAAQhB,UAAW,GAAKA,UAAW,IAE1C,GAAa,OAARS,EASJ,IANCS,EADI1B,EAAiBiB,GACfU,EAAgBV,EAAK,GAChBnB,EAAgBmB,GACrBW,EAAeX,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAIQ,EAAIjB,OAAQS,IAC5BQ,EAAKR,GAAM,EAGb,OAAOD,CACP,IA1LDM,EAAaC,EAAQ,QAwMrB,SAAeK,GACd,IAAIb,EACAc,EACAZ,EACJ,GAAKa,EAAkBF,IAASA,EAAIG,OACnCH,EAAMA,EAAIG,YACJ,IAAMC,EAAeJ,GAC3B,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAEvC,GAAKA,EAAIK,WAAa,EAAI,CAQzB,IAPAlB,EAAImB,EAAOb,EAAMO,EAAIK,aAGrBlB,EAAIoB,EAAKhC,EAAKK,OAAO,EAAGO,GAGxBc,EAAI1B,EAAMY,GACJE,EAAI,EAAGA,EAAIY,EAAErB,OAAQS,IAC1B,GAAKY,EAAGZ,KAAQW,EACf,OAAO,EAITC,EAAEX,KAAMU,EACR,CACD,OAAO,CACP,IAjODN,EAAaC,EAAQ,SAwOrB,WACC,IAAIN,EACJ,IAAMA,EAAI,EAAGA,EAAId,EAAKK,OAAQS,IAC7Bd,EAAMc,GAAIT,OAAS,EAEpBN,EAAS,CACT,IA7ODoB,EAAaC,EAAQ,gBAAiBnB,EAAKE,eAC3C8B,EAAqBb,EAAQ,UAU7B,WACC,OAAOrB,CACP,IAVMqB,EAmDP,SAASc,EAAYC,EAAMC,EAAKC,GAC/B,IAAIZ,EACJ,OAAa,IAARW,EACG,IAAID,EAAM,GAGL,QADbV,EArCD,SAAsBb,GACrB,IAAIa,EACAX,EAMJ,OAHAA,EAAII,EAAMN,IAGDZ,EAAKK,QAAUL,EAAMc,GAAIT,OAC1BL,EAAMc,GAAIwB,MAGbvC,EAAOa,EAAIX,EAAKE,cACb,MAERsB,EAAM,IAAIc,EAAa3B,GAGvBb,GAAUa,EAEHa,EACP,CAgBMe,CAAaC,EAAOL,GAAMM,EAAmBL,KAE3CZ,EAED,IAAIU,EAAMV,EAAK,EAAGW,EACzB,CAkBD,SAAShB,IACR,IAAIC,EACAgB,EACAF,EACAxC,EACAkB,EACA8B,EACArD,EACA8C,EACAtB,EAUJ,GALCuB,GAHDhB,EAAQjB,UAAUC,SACJuC,EAAUxC,UAAWiB,EAAM,IAEhCjB,UADRiB,GAAS,GAGDjC,EAGK,QADd+C,EAAO3C,EAAO6C,IAEb,MAAM,IAAI5B,UAAWC,EAAQ,QAAS2B,IAEvC,GAAKhB,GAAS,EACb,OAAO,IAAIc,EAAM,GAGlB,GAAK3B,EAAsBJ,UAAW,IACrC,OAAO8B,EAAYC,EAAM/B,UAAW,GAAKiC,GAG1C,GAAKQ,EAAczC,UAAW,IAAQ,CAYrC,GAVAgC,GADAzC,EAAMS,UAAW,IACPC,OACLyC,EAAmBnD,GACvBA,EAAM4B,EAAgB5B,EAAK,GAChBoD,EAAkBpD,GAC7BA,EAAM6B,EAAe7B,EAAK,GACf,WAAWqD,KAAMX,KAE5BD,GAAO,GAGK,QADbvB,EAAMqB,EAAYC,EAAMC,EAAKC,IAE5B,OAAOxB,EAER,GAAKjB,EAAiBiB,IAASnB,EAAgBmB,GAE9C,OADAA,EAAI8B,IAAKhD,GACFkB,EAKR,IAFAvB,EAAM2D,EAAetD,GACrBgD,EAAMO,EAAerC,GACfC,EAAI,EAAGA,EAAIsB,EAAKtB,IACrB6B,EAAK9B,EAAKC,EAAGxB,EAAKK,EAAKmB,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,QAASN,UAAW,IACjD,CAkGF,CIrTG,IAAC+C,EAAiBtD,ICPrBsB,EAAAiC,EAAA,UAAAvD"} \ No newline at end of file diff --git a/lib/bytes_per_element.json b/lib/bytes_per_element.json deleted file mode 100644 index f97fe70..0000000 --- a/lib/bytes_per_element.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "float64": 8, - "float32": 4, - "int16": 2, - "int32": 4, - "int8": 1, - "uint16": 2, - "uint32": 4, - "uint8": 1, - "uint8c": 1, - "complex64": 8, - "complex128": 16 -} diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index a421711..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +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'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'highWaterMark': 9007199254740992 - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 3fe17ca..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,372 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var isComplex64Array = require( '@stdlib/assert-is-complex64array' ); -var isComplex128Array = require( '@stdlib/assert-is-complex128array' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var ctors = require( '@stdlib/array-typed-ctors' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var resolveSetter = require( '@stdlib/array-base-resolve-setter' ); -var ARRAY_DEFAULTS = require( '@stdlib/array-defaults' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil = require( '@stdlib/math-base-special-ceil' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); -var log2 = require( '@stdlib/math-base-special-log2' ); -var min = require( '@stdlib/math-base-special-min' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var createPool = require( './pool.js' ); -var BYTES_PER_ELEMENT = require( './bytes_per_element.json' ); - - -// VARIABLES // - -var DEFAULT_DTYPE = ARRAY_DEFAULTS.get( 'dtypes.default' ); -var Complex64Array = ctors( 'complex64' ); -var Complex128Array = ctors( 'complex128' ); - - -// FUNCTIONS // - -/** -* Tests whether an array is a single-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a single-precision complex floating-point number array -*/ -function isCmplx64Array( arr ) { - return ( arr instanceof Complex64Array ); -} - -/** -* Tests whether an array is a double-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a double-precision complex floating-point number array -*/ -function isCmplx128Array( arr ) { - return ( arr instanceof Complex128Array ); -} - - -// MAIN // - -/** -* Creates a typed array pool. -* -* @param {Options} [options] - pool options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} allocator -* -* @example -* var typedarraypool = factory(); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -function factory( options ) { - var nbytes; - var pool; - var opts; - var err; - - opts = defaults(); - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - pool = createPool( ceil( log2( opts.highWaterMark ) ) ); - nbytes = 0; - - setReadOnly( malloc, 'malloc', malloc ); // circular reference - setReadOnly( malloc, 'calloc', calloc ); - setReadOnly( malloc, 'free', free ); - setReadOnly( malloc, 'clear', clear ); - setReadOnly( malloc, 'highWaterMark', opts.highWaterMark ); - setReadOnlyAccessor( malloc, 'nbytes', getBytes ); - - return malloc; - - /** - * Returns the number of allocated bytes. - * - * @private - * @returns {NonNegativeInteger} number of allocated bytes - */ - function getBytes() { - return nbytes; - } - - /** - * Returns an array buffer. - * - * @private - * @param {NonNegativeInteger} n - number of bytes - * @returns {(ArrayBuffer|null)} array buffer or null - */ - function arraybuffer( n ) { - var buf; - var i; - - // Convert the number of bytes to an index in our pool table: - i = log2( n ); - - // If we already have an available array buffer, use it... - if ( i < pool.length && pool[ i ].length ) { - return pool[ i ].pop(); - } - // Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate... - if ( nbytes+n > opts.highWaterMark ) { - return null; - } - buf = new ArrayBuffer( n ); - - // Update the running counter of allocated bytes: - nbytes += n; - - return buf; - } - - /** - * Returns a typed array. - * - * @private - * @param {Function} ctor - typed array constructor - * @param {NonNegativeInteger} len - view length - * @param {string} dtype - data type - * @returns {(TypedArray|null)} typed array or null - */ - function typedarray( ctor, len, dtype ) { - var buf; - if ( len === 0 ) { - return new ctor( 0 ); - } - buf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] ); - if ( buf === null ) { - return buf; - } - return new ctor( buf, 0, len ); - } - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length or an array-like object - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function malloc() { - var nargs; - var dtype; - var ctor; - var arr; - var out; - var set; - var get; - var len; - var i; - - nargs = arguments.length; - if ( nargs && isString( arguments[ nargs-1 ] ) ) { - nargs -= 1; - dtype = arguments[ nargs ]; - } else { - dtype = DEFAULT_DTYPE; - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( '01H2Y', dtype ) ); - } - if ( nargs <= 0 ) { - return new ctor( 0 ); - } - // Check if provided a typed array length... - if ( isNonNegativeInteger( arguments[ 0 ] ) ) { - return typedarray( ctor, arguments[ 0 ], dtype ); - } - // Check if provided an array-like object containing data elements... - if ( isCollection( arguments[ 0 ] ) ) { - arr = arguments[ 0 ]; - len = arr.length; - if ( isComplex128Array( arr ) ) { - arr = reinterpret128( arr, 0 ); - } else if ( isComplex64Array( arr ) ) { - arr = reinterpret64( arr, 0 ); - } else if ( /^complex/.test( dtype ) ) { - // Assume we've been provided an array of interleaved real and imaginary components... - len /= 2; - } - out = typedarray( ctor, len, dtype ); - if ( out === null ) { - return out; - } - if ( isCmplx128Array( out ) || isCmplx64Array( out ) ) { - out.set( arr ); - return out; - } - // Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other "unsafe" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things... - get = resolveGetter( arr ); - set = resolveSetter( out ); - for ( i = 0; i < len; i++ ) { - set( out, i, get( arr, i ) ); - } - return out; - } - throw new TypeError( format( '01H2r', arguments[ 0 ] ) ); - } - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {NonNegativeInteger} [len=0] - array length - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function calloc() { - var nargs; - var out; - var tmp; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - out = malloc(); - } else if ( nargs === 1 ) { - out = malloc( arguments[ 0 ] ); - } else { - out = malloc( arguments[ 0 ], arguments[ 1 ] ); - } - if ( out !== null ) { - // Initialize the memory... - if ( isCmplx128Array( out ) ) { - tmp = reinterpret128( out, 0 ); - } else if ( isCmplx64Array( out ) ) { - tmp = reinterpret64( out, 0 ); - } else { - tmp = out; - } - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = 0.0; - } - } - return out; - } - - /** - * Frees a typed array or typed array buffer. - * - * ## Notes - * - * - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., "freeing" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool. - * - * @private - * @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free - * @throws {TypeError} must provide a typed array or typed array buffer - * @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed - */ - function free( buf ) { - var n; - var p; - var i; - if ( isTypedArrayLike( buf ) && buf.buffer ) { - buf = buf.buffer; - } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( '01H2s', buf ) ); - } - if ( buf.byteLength > 0 ) { - n = floor( log2( buf.byteLength ) ); - - // Prohibit "freeing" array buffers which would potentially allow users to circumvent high water mark limits: - n = min( pool.length-1, n ); - - // Ensure that we do not attempt to free the same buffer more than once... - p = pool[ n ]; - for ( i = 0; i < p.length; i++ ) { - if ( p[ i ] === buf ) { - return false; - } - } - // Add the buffer to our pool of free buffers: - p.push( buf ); - } - return true; - } - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @private - */ - function clear() { - var i; - for ( i = 0; i < pool.length; i++ ) { - pool[ i ].length = 0; - } - nbytes = 0; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6c12a4e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Typed array pool. -* -* @module @stdlib/array-pool -* -* @example -* var typedarraypool = require( '@stdlib/array-pool' ); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8f69ee3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,63 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @name typedarraypool -* @type {Function} -* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a valid array length or an array-like object -* @throws {TypeError} must provide a recognized data type -* @returns {(TypedArray|null)} typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -var typedarraypool = factory(); - - -// EXPORTS // - -module.exports = typedarraypool; diff --git a/lib/pool.js b/lib/pool.js deleted file mode 100644 index 5abd287..0000000 --- a/lib/pool.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Initializes a cache for pooled typed array buffers. -* -* @private -* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size -* @returns {ArrayArray} initialized cache -*/ -function pool( n ) { - var out; - var i; - - out = []; - for ( i = 0; i < n+1; i++ ) { - out.push( [] ); - } - return out; -} - - -// EXPORTS // - -module.exports = pool; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index da746bb..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'highWaterMark': 1024 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '01H2V', options ) ); - } - if ( hasOwnProp( options, 'highWaterMark' ) ) { - opts.highWaterMark = options.highWaterMark; - if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 8ad9b84..ce31461 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Typed array pool.", "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,78 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-resolve-getter": "^0.2.1", - "@stdlib/array-base-resolve-setter": "^0.2.1", - "@stdlib/array-buffer": "^0.2.1", - "@stdlib/array-defaults": "^0.2.1", - "@stdlib/array-typed-ctors": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-arraybuffer": "^0.2.1", - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-complex128array": "^0.2.1", - "@stdlib/assert-is-complex64array": "^0.2.1", - "@stdlib/assert-is-nonnegative-integer": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/assert-is-string": "^0.2.1", - "@stdlib/assert-is-typed-array-like": "^0.2.1", - "@stdlib/math-base-special-ceil": "^0.2.1", - "@stdlib/math-base-special-ceil2": "^0.2.1", - "@stdlib/math-base-special-floor": "^0.2.1", - "@stdlib/math-base-special-log2": "^0.2.1", - "@stdlib/math-base-special-min": "^0.2.1", - "@stdlib/strided-base-reinterpret-complex128": "^0.2.1", - "@stdlib/strided-base-reinterpret-complex64": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.2.1", - "@stdlib/array-complex64": "^0.2.1", - "@stdlib/array-float32": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/array-int16": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/array-int8": "^0.2.1", - "@stdlib/array-uint16": "^0.2.1", - "@stdlib/array-uint32": "^0.2.1", - "@stdlib/array-uint8": "^0.2.1", - "@stdlib/array-uint8c": "^0.2.1", - "@stdlib/assert-instance-of": "^0.2.1", - "@stdlib/assert-is-complex-typed-array": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-typed-array": "^0.2.1", - "@stdlib/complex-float32": "^0.2.1", - "@stdlib/complex-float64": "^0.2.1", - "@stdlib/complex-imag": "^0.2.1", - "@stdlib/complex-imagf": "^0.2.1", - "@stdlib/complex-real": "^0.2.1", - "@stdlib/complex-realf": "^0.2.1", - "@stdlib/math-base-special-pow": "^0.2.1", - "@stdlib/random-base-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..83e2e4e --- /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.factory.js b/test/test.factory.js deleted file mode 100644 index 396aee2..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,2240 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function (no options)', function test( t ) { - t.strictEqual( typeof factory(), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - t.strictEqual( typeof factory( {} ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided a `highWaterMark` option which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (length)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a function which returns a typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, length)', function test( t ) { - var typedarraypool = factory(); - var arr; - - arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a `malloc` method which is a circular reference', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - var buf; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the returned function is a property which returns the pool\'s high water mark', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function supports specifying a high water mark which limits the total amount of memory a pool can allocate', function test( t ) { - var typedarraypool; - var arr1; - var arr2; - - typedarraypool = factory({ - 'highWaterMark': 64 // bytes - }); - - typedarraypool.clear(); - - arr1 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr1.length, 8, 'returns expected value' ); - t.strictEqual( arr1.byteLength, 64, 'returns expected value' ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - typedarraypool.free( arr1 ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Create an array which is less than or equal to the high water mark: - arr2 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr2.length, 8, 'returns expected value' ); - t.strictEqual( arr2.byteLength, 64, 'returns expected value' ); - - typedarraypool.free( arr2 ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a property which returns the total number of accumulated bytes', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var typedarraypool; - var arrs; - var i; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 54aa5ee..0000000 --- a/test/test.js +++ /dev/null @@ -1,1797 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var typedarraypool = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -}); From a60c0ee44b69bedaa9a60cb3b0ac3d11bcd3dcad Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 07:29:33 +0000 Subject: [PATCH 080/103] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 4365791..3fe17ca 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -35,7 +35,7 @@ var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); var resolveSetter = require( '@stdlib/array-base-resolve-setter' ); var ARRAY_DEFAULTS = require( '@stdlib/array-defaults' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ArrayBuffer = require( '@stdlib/array-buffer' ); var ceil = require( '@stdlib/math-base-special-ceil' ); var floor = require( '@stdlib/math-base-special-floor' ); @@ -228,7 +228,7 @@ function factory( options ) { } ctor = ctors( dtype ); if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '01H2Y', dtype ) ); } if ( nargs <= 0 ) { return new ctor( 0 ); @@ -265,7 +265,7 @@ function factory( options ) { } return out; } - throw new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) ); + throw new TypeError( format( '01H2r', arguments[ 0 ] ) ); } /** @@ -331,7 +331,7 @@ function factory( options ) { if ( isTypedArrayLike( buf ) && buf.buffer ) { buf = buf.buffer; } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) ); + throw new TypeError( format( '01H2s', buf ) ); } if ( buf.byteLength > 0 ) { n = floor( log2( buf.byteLength ) ); diff --git a/lib/validate.js b/lib/validate.js index ce54890..da746bb 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '01H2V', options ) ); } if ( hasOwnProp( options, 'highWaterMark' ) ) { opts.highWaterMark = options.highWaterMark; if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) ); + return new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) ); } } return null; diff --git a/package.json b/package.json index 62f1f6e..243a265 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "@stdlib/math-base-special-min": "^0.2.1", "@stdlib/strided-base-reinterpret-complex128": "^0.2.1", "@stdlib/strided-base-reinterpret-complex64": "^0.2.0", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", From bd29f016f96e6571565879d22bc44076b834d9bf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 12:58:03 +0000 Subject: [PATCH 081/103] Remove files --- index.d.ts | 359 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5206 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 0f5442f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,359 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike, RealOrComplexTypedArray, NumericDataType as DataType } from '@stdlib/types/array'; -import ArrayBuffer = require( '@stdlib/array-buffer' ); - -/** -* Typed array or null. -*/ -type TypedArrayOrNull = RealOrComplexTypedArray | null; - -/** -* Interface defining pool options. -*/ -interface Options { - /** - * Maximum total memory which can be allocated. - */ - highWaterMark?: number; -} - -/** -* Pool interface. -*/ -interface Pool { - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr = typedarraypool(); - * // returns [] - * - * @example - * var arr = typedarraypool( 'float32' ); - * // returns [] - */ - ( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * // Allocate an array of doubles: - * var arr = typedarraypool( 5, 'float64' ); - * // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * typedarraypool.free( arr ); - * - * @example - * var arr1 = typedarraypool( [ 0.5, 0.5, 0.5 ] ); - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * @example - * var arr1 = [ 0.5, 0.5, 0.5 ]; - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - */ - ( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc(); - * // returns [] - * - * var arr2 = typedarraypool.calloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param length - typed array length - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc( 5 ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * var arr2 = typedarraypool.calloc( 5, 'uint8' ); - * // returns [ 0, 0, 0, 0, 0 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( length: number, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc(); - * // returns [] - * - * var arr2 = typedarraypool.malloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc( 5 ); - * // returns - * - * var arr2 = typedarraypool.malloc( 5, 'uint8' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 5.0, -3.0, 2.0 ] ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr2 = typedarraypool.malloc( arr1 ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr3 = typedarraypool.malloc( arr1, 'int32' ); - * // returns [ 5, -3, 2 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * typedarraypool.free( arr3 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ] ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * var arr2 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ], 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Frees a typed array or typed array buffer for use in a future allocation. - * - * @param buf - typed array or typed array buffer to free - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array for use in a future allocation: - * typedarraypool.free( arr ); - * - * // Create another typed array: - * arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array buffer for use in a future allocation: - * typedarraypool.free( arr.buffer ); - */ - free( buf: RealOrComplexTypedArray | ArrayBuffer ): void; - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr ); - * - * // ... - * - * // Clear all freed buffers: - * typedarraypool.clear(); - */ - clear(): void; - - /** - * Read-only property returning the pool's high water mark. - * - * ## Notes - * - * - Once a high water mark is reached, typed array allocation fails. - * - * @example - * var limit = typedarraypool.highWaterMark; - * // returns - */ - readonly highWaterMark: number; - - /** - * Read-only property returning the total number of allocated bytes. - * - * @example - * var arr = typedarraypool( 5, 'float64' ); - * - * var nbytes = typedarraypool.nbytes; - * // returns - */ - readonly nbytes: number; - - /** - * Creates a typed array pool. - * - * @param options - pool options - * @param options.highWaterMark - maximum total memory which can be allocated - * @throws must provide valid options - * @returns allocator - * - * @example - * var allocator = typedarraypool.factory(); - * - * // Allocate an array of doubles: - * var arr = allocator( 5, 'float64' ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * allocator.free( arr ); - */ - factory( options?: Options ): Pool; -} - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @param arg - an array length or an array-like object -* @param dtype - data type (default: 'float64') -* @returns typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -declare var typedarraypool: Pool; - - -// EXPORTS // - -export = typedarraypool; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5787351..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.2.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-setter@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/array-defaults@v0.2.1-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.2.1-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.2.1-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.2.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.2.1-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";var M={float64:8,float32:4,int16:2,int32:4,int8:1,uint16:2,uint32:4,uint8:1,uint8c:1,complex64:8,complex128:16},W=j.get("dtypes.default"),E=d("complex64"),H=d("complex128");function T(e){return e instanceof E}function L(e){return e instanceof H}function P(j){var E,H,P,V;if(P={highWaterMark:9007199254740992},arguments.length&&(V=function(e,t){return w(t)?k(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(c("01H2t","highWaterMark",e.highWaterMark)):null:new TypeError(c("01H2V",t))}(P,j),V))throw V;return H=function(e){var t,r;for(t=[],r=0;r0){for(t=u(x(e.byteLength)),t=y(H.length-1,t),r=H[t],s=0;sP.highWaterMark?null:(t=new v(e),E+=e,t)}(b(t)*M[r]))?s:new e(s,0,t)}function q(){var e,i,n,l,j,v,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:W,null===(n=d(i)))throw new TypeError(c("01H2Y",i));if(e<=0)return new n(0);if(r(arguments[0]))return Y(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,o(l)?l=h(l,0):m(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=Y(n,u,i)))return j;if(L(j)||T(j))return j.set(l),j;for(g=p(l),v=f(j),b=0;b[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '01H2Y', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = resolveGetter( arr );\n\t\t\tset = resolveSetter( out );\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '01H2r', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( '01H2s', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'highWaterMark': 1024\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '01H2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'highWaterMark' ) ) {\n\t\topts.highWaterMark = options.highWaterMark;\n\t\tif ( !isNonNegativeInteger( opts.highWaterMark ) ) {\n\t\t\treturn new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Initializes a cache for pooled typed array buffers.\n*\n* @private\n* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size\n* @returns {ArrayArray} initialized cache\n*/\nfunction pool( n ) {\n\tvar out;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < n+1; i++ ) {\n\t\tout.push( [] );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default pool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DEFAULT_DTYPE","ARRAY_DEFAULTS","get","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","options","nbytes","pool","opts","err","highWaterMark","arguments","length","isObject","hasOwnProp","isNonNegativeInteger","TypeError","format","validate","n","out","i","push","createPool","ceil","log2","setReadOnly","malloc","nargs","tmp","reinterpret128","reinterpret64","buf","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","setReadOnlyAccessor","typedarray","ctor","len","dtype","pop","ArrayBuffer","arraybuffer","ceil2","BYTES_PER_ELEMENT","set","isString","isCollection","isComplex128Array","isComplex64Array","test","resolveGetter","resolveSetter","typedarraypool","main"],"mappings":";;q+EAoDIA,EAAgBC,EAAeC,IAAK,kBACpCC,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,ECjFO,CACNE,cAAiB,kBDiFbC,UAAUC,SACdH,EEnEF,SAAmBD,EAAMH,GACxB,OAAMQ,EAAUR,GAGXS,EAAYT,EAAS,mBACzBG,EAAKE,cAAgBL,EAAQK,eACvBK,EAAsBP,EAAKE,gBACzB,IAAIM,UAAWC,EAAQ,QAAS,gBAAiBT,EAAKE,gBAGxD,KARC,IAAIM,UAAWC,EAAQ,QAASZ,GASzC,CFwDQa,CAAUV,EAAMH,GACjBI,GACJ,MAAMA,EAaR,OAVAF,EG5FD,SAAeY,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,CHmFQG,CAAYC,EAAMC,EAAMjB,EAAKE,iBACpCJ,EAAS,EAEToB,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,UA+JrB,WACC,IAAIC,EACAR,EACAS,EACAR,EAEJO,EAAQjB,UAAUC,OAEjBQ,EADc,IAAVQ,EACED,IACe,IAAVC,EACLD,EAAQhB,UAAW,IAEnBgB,EAAQhB,UAAW,GAAKA,UAAW,IAE1C,GAAa,OAARS,EASJ,IANCS,EADI1B,EAAiBiB,GACfU,EAAgBV,EAAK,GAChBnB,EAAgBmB,GACrBW,EAAeX,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAIQ,EAAIjB,OAAQS,IAC5BQ,EAAKR,GAAM,EAGb,OAAOD,CACP,IA1LDM,EAAaC,EAAQ,QAwMrB,SAAeK,GACd,IAAIb,EACAc,EACAZ,EACJ,GAAKa,EAAkBF,IAASA,EAAIG,OACnCH,EAAMA,EAAIG,YACJ,IAAMC,EAAeJ,GAC3B,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAEvC,GAAKA,EAAIK,WAAa,EAAI,CAQzB,IAPAlB,EAAImB,EAAOb,EAAMO,EAAIK,aAGrBlB,EAAIoB,EAAKhC,EAAKK,OAAO,EAAGO,GAGxBc,EAAI1B,EAAMY,GACJE,EAAI,EAAGA,EAAIY,EAAErB,OAAQS,IAC1B,GAAKY,EAAGZ,KAAQW,EACf,OAAO,EAITC,EAAEX,KAAMU,EACR,CACD,OAAO,CACP,IAjODN,EAAaC,EAAQ,SAwOrB,WACC,IAAIN,EACJ,IAAMA,EAAI,EAAGA,EAAId,EAAKK,OAAQS,IAC7Bd,EAAMc,GAAIT,OAAS,EAEpBN,EAAS,CACT,IA7ODoB,EAAaC,EAAQ,gBAAiBnB,EAAKE,eAC3C8B,EAAqBb,EAAQ,UAU7B,WACC,OAAOrB,CACP,IAVMqB,EAmDP,SAASc,EAAYC,EAAMC,EAAKC,GAC/B,IAAIZ,EACJ,OAAa,IAARW,EACG,IAAID,EAAM,GAGL,QADbV,EArCD,SAAsBb,GACrB,IAAIa,EACAX,EAMJ,OAHAA,EAAII,EAAMN,IAGDZ,EAAKK,QAAUL,EAAMc,GAAIT,OAC1BL,EAAMc,GAAIwB,MAGbvC,EAAOa,EAAIX,EAAKE,cACb,MAERsB,EAAM,IAAIc,EAAa3B,GAGvBb,GAAUa,EAEHa,EACP,CAgBMe,CAAaC,EAAOL,GAAMM,EAAmBL,KAE3CZ,EAED,IAAIU,EAAMV,EAAK,EAAGW,EACzB,CAkBD,SAAShB,IACR,IAAIC,EACAgB,EACAF,EACAxC,EACAkB,EACA8B,EACArD,EACA8C,EACAtB,EAUJ,GALCuB,GAHDhB,EAAQjB,UAAUC,SACJuC,EAAUxC,UAAWiB,EAAM,IAEhCjB,UADRiB,GAAS,GAGDjC,EAGK,QADd+C,EAAO3C,EAAO6C,IAEb,MAAM,IAAI5B,UAAWC,EAAQ,QAAS2B,IAEvC,GAAKhB,GAAS,EACb,OAAO,IAAIc,EAAM,GAGlB,GAAK3B,EAAsBJ,UAAW,IACrC,OAAO8B,EAAYC,EAAM/B,UAAW,GAAKiC,GAG1C,GAAKQ,EAAczC,UAAW,IAAQ,CAYrC,GAVAgC,GADAzC,EAAMS,UAAW,IACPC,OACLyC,EAAmBnD,GACvBA,EAAM4B,EAAgB5B,EAAK,GAChBoD,EAAkBpD,GAC7BA,EAAM6B,EAAe7B,EAAK,GACf,WAAWqD,KAAMX,KAE5BD,GAAO,GAGK,QADbvB,EAAMqB,EAAYC,EAAMC,EAAKC,IAE5B,OAAOxB,EAER,GAAKjB,EAAiBiB,IAASnB,EAAgBmB,GAE9C,OADAA,EAAI8B,IAAKhD,GACFkB,EAKR,IAFAvB,EAAM2D,EAAetD,GACrBgD,EAAMO,EAAerC,GACfC,EAAI,EAAGA,EAAIsB,EAAKtB,IACrB6B,EAAK9B,EAAKC,EAAGxB,EAAKK,EAAKmB,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,QAASN,UAAW,IACjD,CAkGF,CIrTG,IAAC+C,EAAiBtD,ICPrBsB,EAAAiC,EAAA,UAAAvD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 83e2e4e..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 6c47d23bd4e98f1ee10eb5a6914b8fde7443fefe Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 12:58:21 +0000 Subject: [PATCH 082/103] 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 | 45 +- SECURITY.md | 5 - benchmark/benchmark.calloc.js | 246 -- benchmark/benchmark.factory.js | 71 - benchmark/benchmark.js | 246 -- benchmark/benchmark.length.complex128.js | 102 - benchmark/benchmark.length.complex64.js | 102 - benchmark/benchmark.length.float32.js | 102 - benchmark/benchmark.length.float64.js | 102 - benchmark/benchmark.length.int16.js | 102 - benchmark/benchmark.length.int32.js | 102 - benchmark/benchmark.length.int8.js | 102 - benchmark/benchmark.length.uint16.js | 102 - benchmark/benchmark.length.uint32.js | 102 - benchmark/benchmark.length.uint8.js | 102 - benchmark/benchmark.length.uint8c.js | 102 - benchmark/benchmark.malloc.js | 246 -- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 347 -- docs/types/test.ts | 193 - examples/index.js | 80 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/bytes_per_element.json | 13 - lib/defaults.js | 42 - lib/factory.js | 372 -- lib/index.js | 56 - lib/main.js | 63 - lib/pool.js | 44 - lib/validate.js | 66 - package.json | 99 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 2240 ---------- test/test.js | 1797 -------- 63 files changed, 4871 insertions(+), 10650 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.calloc.js delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.complex128.js delete mode 100644 benchmark/benchmark.length.complex64.js delete mode 100644 benchmark/benchmark.length.float32.js delete mode 100644 benchmark/benchmark.length.float64.js delete mode 100644 benchmark/benchmark.length.int16.js delete mode 100644 benchmark/benchmark.length.int32.js delete mode 100644 benchmark/benchmark.length.int8.js delete mode 100644 benchmark/benchmark.length.uint16.js delete mode 100644 benchmark/benchmark.length.uint32.js delete mode 100644 benchmark/benchmark.length.uint8.js delete mode 100644 benchmark/benchmark.length.uint8c.js delete mode 100644 benchmark/benchmark.malloc.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/bytes_per_element.json delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/pool.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index f79a150..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T05:12:04.247Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ea35f20..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/array/pool) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6f7c875..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/array/pool) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 869c4e9..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -495,7 +492,7 @@ console.log( 'nbytes: %d', typedarray.nbytes ); ## 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]. @@ -564,7 +561,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/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.calloc.js b/benchmark/benchmark.calloc.js deleted file mode 100644 index fd8f53d..0000000 --- a/benchmark/benchmark.calloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':calloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 58918bb..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = typedarray.factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:highWaterMark', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'highWaterMark': 0 - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.highWaterMark = i; - f = typedarray.factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 4310559..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.complex128.js b/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 12c6668..0000000 --- a/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex64.js b/benchmark/benchmark.length.complex64.js deleted file mode 100644 index ca2b45c..0000000 --- a/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float32.js b/benchmark/benchmark.length.float32.js deleted file mode 100644 index b3b4508..0000000 --- a/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float64.js b/benchmark/benchmark.length.float64.js deleted file mode 100644 index 5f0132d..0000000 --- a/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int16.js b/benchmark/benchmark.length.int16.js deleted file mode 100644 index 9f253cb..0000000 --- a/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int32.js b/benchmark/benchmark.length.int32.js deleted file mode 100644 index f83e795..0000000 --- a/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int8.js b/benchmark/benchmark.length.int8.js deleted file mode 100644 index 5b01174..0000000 --- a/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint16.js b/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 32b0a5d..0000000 --- a/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint32.js b/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 290b90c..0000000 --- a/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8.js b/benchmark/benchmark.length.uint8.js deleted file mode 100644 index ff7d733..0000000 --- a/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8c.js b/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index 8f0d10a..0000000 --- a/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.malloc.js b/benchmark/benchmark.malloc.js deleted file mode 100644 index 1661907..0000000 --- a/benchmark/benchmark.malloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':malloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 612de17..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/array/pool" -%% click B href "https://github.com/stdlib-js/array-pool/tree/main" -%% click C href "https://github.com/stdlib-js/array-pool/tree/production" -%% click D href "https://github.com/stdlib-js/array-pool/tree/esm" -%% click E href "https://github.com/stdlib-js/array-pool/tree/deno" -%% click F href "https://github.com/stdlib-js/array-pool/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/pool -[production-url]: https://github.com/stdlib-js/array-pool/tree/production -[deno-url]: https://github.com/stdlib-js/array-pool/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-pool/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-pool/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-pool/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-pool/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-pool/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 5160b6f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import typedarraypool from '../docs/types/index'; -export = typedarraypool; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4f5b474..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var l=function(n,i){return function(){return i||n((i={exports:{}}).exports,i),i.exports}};var M=l(function(Er,w){ -function I(){return{highWaterMark:9007199254740992}}w.exports=I -});var T=l(function(Tr,E){ -var U=require('@stdlib/assert-is-plain-object/dist'),z=require('@stdlib/assert-has-own-property/dist'),G=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,k=require('@stdlib/error-tools-fmtprodmsg/dist');function H(n,i){return U(i)?z(i,"highWaterMark")&&(n.highWaterMark=i.highWaterMark,!G(n.highWaterMark))?new TypeError(k('01H2t',"highWaterMark",n.highWaterMark)):null:new TypeError(k('01H2V',i));}E.exports=H -});var C=l(function(Wr,W){ -function J(n){var i,u;for(i=[],u=0;uv.highWaterMark?null:(e=new or(r),i+=r,e)}function d(r,e,a){var t;return e===0?new r(0):(t=j(vr(e)*mr[a]),t===null?t:new r(t,0,e))}function o(){var r,e,a,t,s,x,A,c,f;if(r=arguments.length,r&&Q(arguments[r-1])?(r-=1,e=arguments[r]):e=pr,a=y(e),a===null)throw new TypeError(m('01H2Y',e));if(r<=0)return new a(0);if(X(arguments[0]))return d(a,arguments[0],e);if(Z(arguments[0])){if(t=arguments[0],c=t.length,tr(t)?t=b(t,0):er(t)?t=P(t,0):/^complex/.test(e)&&(c/=2),s=d(a,c,e),s===null)return s;if(R(s)||L(s))return s.set(t),s;for(A=ir(t),x=nr(s),f=0;f0){for(e=lr(p(r.byteLength)),e=fr(u.length-1,e),a=u[e],t=0;t[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = resolveGetter( arr );\n\t\t\tset = resolveSetter( out );\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nmodule.exports = typedarraypool;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* var typedarraypool = require( '@stdlib/array-pool' );\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,cAAiB,gBAClB,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,eAAgB,IACzCD,EAAK,cAAgBC,EAAQ,cACxB,CAACJ,EAAsBG,EAAK,aAAc,GACvC,IAAI,UAAWF,EAAQ,2EAA4E,gBAAiBE,EAAK,aAAc,CAAE,EAG3I,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cA6BA,SAASC,EAAM,EAAI,CAClB,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAI,EAAE,EAAGA,IACrBD,EAAI,KAAM,CAAC,CAAE,EAEd,OAAOA,CACR,CAKAF,EAAO,QAAUC,IC3CjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,QAAW,EACX,QAAW,EACX,MAAS,EACT,MAAS,EACT,KAAQ,EACR,OAAU,EACV,OAAU,EACV,MAAS,EACT,OAAU,EACT,UAAa,EACb,WAAc,EAChB,ICZA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAe,QAAS,8BAA+B,EACvDC,EAAmB,QAAS,oCAAqC,EACjEC,GAAgB,QAAS,+BAAgC,EACzDC,GAAmB,QAAS,kCAAmC,EAC/DC,GAAoB,QAAS,mCAAoC,EACjEC,EAAc,QAAS,uDAAwD,EAC/EC,GAAsB,QAAS,uDAAwD,EACvFC,EAAQ,QAAS,2BAA4B,EAC7CC,EAAgB,QAAS,4CAA6C,EACtEC,EAAiB,QAAS,6CAA8C,EACxEC,GAAgB,QAAS,mCAAoC,EAC7DC,GAAgB,QAAS,mCAAoC,EAC7DC,GAAiB,QAAS,wBAAyB,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,GAAc,QAAS,sBAAuB,EAC9CC,GAAO,QAAS,gCAAiC,EACjDC,GAAQ,QAAS,iCAAkC,EACnDC,GAAQ,QAAS,iCAAkC,EACnDC,EAAO,QAAS,gCAAiC,EACjDC,GAAM,QAAS,+BAAgC,EAC/CC,GAAW,IACXC,GAAW,IACXC,GAAa,IACbC,GAAoB,IAKpBC,GAAgBZ,GAAe,IAAK,gBAAiB,EACrDa,GAAiBlB,EAAO,WAAY,EACpCmB,GAAkBnB,EAAO,YAAa,EAY1C,SAASoB,EAAgBC,EAAM,CAC9B,OAASA,aAAeH,EACzB,CASA,SAASI,EAAiBD,EAAM,CAC/B,OAASA,aAAeF,EACzB,CA6BA,SAASI,GAASC,EAAU,CAC3B,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,EAAOd,GAAS,EACX,UAAU,SACde,EAAMd,GAAUa,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAAF,EAAOX,GAAYP,GAAMG,EAAMgB,EAAK,aAAc,CAAE,CAAE,EACtDF,EAAS,EAET3B,EAAa+B,EAAQ,SAAUA,CAAO,EACtC/B,EAAa+B,EAAQ,SAAUC,CAAO,EACtChC,EAAa+B,EAAQ,OAAQE,CAAK,EAClCjC,EAAa+B,EAAQ,QAASG,CAAM,EACpClC,EAAa+B,EAAQ,gBAAiBF,EAAK,aAAc,EACzD5B,GAAqB8B,EAAQ,SAAUI,CAAS,EAEzCJ,EAQP,SAASI,GAAW,CACnB,OAAOR,CACR,CASA,SAASS,EAAaC,EAAI,CACzB,IAAIC,EACAC,EAMJ,OAHAA,EAAI1B,EAAMwB,CAAE,EAGPE,EAAIX,EAAK,QAAUA,EAAMW,CAAE,EAAE,OAC1BX,EAAMW,CAAE,EAAE,IAAI,EAGjBZ,EAAOU,EAAIR,EAAK,cACb,MAERS,EAAM,IAAI7B,GAAa4B,CAAE,EAGzBV,GAAUU,EAEHC,EACR,CAWA,SAASE,EAAYC,EAAMC,EAAKC,EAAQ,CACvC,IAAIL,EACJ,OAAKI,IAAQ,EACL,IAAID,EAAM,CAAE,GAEpBH,EAAMF,EAAaxB,GAAO8B,CAAI,EAAExB,GAAmByB,CAAM,CAAE,EACtDL,IAAQ,KACLA,EAED,IAAIG,EAAMH,EAAK,EAAGI,CAAI,EAC9B,CAkBA,SAASX,GAAS,CACjB,IAAIa,EACAD,EACAF,EACAlB,EACAsB,EACAC,EACAC,EACAL,EACAH,EAUJ,GARAK,EAAQ,UAAU,OACbA,GAASnD,EAAU,UAAWmD,EAAM,CAAE,CAAE,GAC5CA,GAAS,EACTD,EAAQ,UAAWC,CAAM,GAEzBD,EAAQxB,GAETsB,EAAOvC,EAAOyC,CAAM,EACfF,IAAS,KACb,MAAM,IAAI,UAAWjC,EAAQ,sEAAuEmC,CAAM,CAAE,EAE7G,GAAKC,GAAS,EACb,OAAO,IAAIH,EAAM,CAAE,EAGpB,GAAK/C,EAAsB,UAAW,CAAE,CAAE,EACzC,OAAO8C,EAAYC,EAAM,UAAW,CAAE,EAAGE,CAAM,EAGhD,GAAKhD,EAAc,UAAW,CAAE,CAAE,EAAI,CAYrC,GAXA4B,EAAM,UAAW,CAAE,EACnBmB,EAAMnB,EAAI,OACLxB,GAAmBwB,CAAI,EAC3BA,EAAMnB,EAAgBmB,EAAK,CAAE,EAClBzB,GAAkByB,CAAI,EACjCA,EAAMpB,EAAeoB,EAAK,CAAE,EACjB,WAAW,KAAMoB,CAAM,IAElCD,GAAO,GAERG,EAAML,EAAYC,EAAMC,EAAKC,CAAM,EAC9BE,IAAQ,KACZ,OAAOA,EAER,GAAKrB,EAAiBqB,CAAI,GAAKvB,EAAgBuB,CAAI,EAClD,OAAAA,EAAI,IAAKtB,CAAI,EACNsB,EAKR,IAFAE,EAAM1C,GAAekB,CAAI,EACzBuB,EAAMxC,GAAeuC,CAAI,EACnBN,EAAI,EAAGA,EAAIG,EAAKH,IACrBO,EAAKD,EAAKN,EAAGQ,EAAKxB,EAAKgB,CAAE,CAAE,EAE5B,OAAOM,CACR,CACA,MAAM,IAAI,UAAWrC,EAAQ,wGAAyG,UAAW,CAAE,CAAE,CAAE,CACxJ,CAgBA,SAASwB,GAAS,CACjB,IAAIY,EACAC,EACAG,EACAT,EAUJ,GARAK,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAMd,EAAO,EACFa,IAAU,EACrBC,EAAMd,EAAQ,UAAW,CAAE,CAAE,EAE7Bc,EAAMd,EAAQ,UAAW,CAAE,EAAG,UAAW,CAAE,CAAE,EAEzCc,IAAQ,KASZ,IAPKrB,EAAiBqB,CAAI,EACzBG,EAAM5C,EAAgByC,EAAK,CAAE,EAClBvB,EAAgBuB,CAAI,EAC/BG,EAAM7C,EAAe0C,EAAK,CAAE,EAE5BG,EAAMH,EAEDN,EAAI,EAAGA,EAAIS,EAAI,OAAQT,IAC5BS,EAAKT,CAAE,EAAI,EAGb,OAAOM,CACR,CAcA,SAASZ,EAAMK,EAAM,CACpB,IAAID,EACAY,EACAV,EACJ,GAAK3C,EAAkB0C,CAAI,GAAKA,EAAI,OACnCA,EAAMA,EAAI,eACC,CAACzC,GAAeyC,CAAI,EAC/B,MAAM,IAAI,UAAW9B,EAAQ,4EAA6E8B,CAAI,CAAE,EAEjH,GAAKA,EAAI,WAAa,EAAI,CAQzB,IAPAD,EAAI1B,GAAOE,EAAMyB,EAAI,UAAW,CAAE,EAGlCD,EAAIvB,GAAKc,EAAK,OAAO,EAAGS,CAAE,EAG1BY,EAAIrB,EAAMS,CAAE,EACNE,EAAI,EAAGA,EAAIU,EAAE,OAAQV,IAC1B,GAAKU,EAAGV,CAAE,IAAMD,EACf,MAAO,GAITW,EAAE,KAAMX,CAAI,CACb,CACA,MAAO,EACR,CAOA,SAASJ,GAAQ,CAChB,IAAIK,EACJ,IAAMA,EAAI,EAAGA,EAAIX,EAAK,OAAQW,IAC7BX,EAAMW,CAAE,EAAE,OAAS,EAEpBZ,EAAS,CACV,CACD,CAKAnC,EAAO,QAAUiC,KCnXjB,IAAAyB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAU,IAmCVC,GAAiBD,GAAQ,EAK7BD,EAAO,QAAUE,KCnBjB,IAAIC,GAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,GAAU,IAKdF,GAAaC,EAAM,UAAWC,EAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isNonNegativeInteger", "format", "validate", "opts", "options", "require_pool", "__commonJSMin", "exports", "module", "pool", "out", "i", "require_bytes_per_element", "__commonJSMin", "exports", "module", "require_factory", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isCollection", "isTypedArrayLike", "isArrayBuffer", "isComplex64Array", "isComplex128Array", "setReadOnly", "setReadOnlyAccessor", "ctors", "reinterpret64", "reinterpret128", "resolveGetter", "resolveSetter", "ARRAY_DEFAULTS", "format", "ArrayBuffer", "ceil", "floor", "ceil2", "log2", "min", "defaults", "validate", "createPool", "BYTES_PER_ELEMENT", "DEFAULT_DTYPE", "Complex64Array", "Complex128Array", "isCmplx64Array", "arr", "isCmplx128Array", "factory", "options", "nbytes", "pool", "opts", "err", "malloc", "calloc", "free", "clear", "getBytes", "arraybuffer", "n", "buf", "i", "typedarray", "ctor", "len", "dtype", "nargs", "out", "set", "get", "tmp", "p", "require_main", "__commonJSMin", "exports", "module", "factory", "typedarraypool", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5244595..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,347 +0,0 @@ - -{{alias}}( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - Memory is **uninitialized**, which means that the contents of a returned - typed array may contain sensitive contents. - - The function supports the following data types: - - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - The default typed array data type is `float64`. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}() - [] - > arr = {{alias}}( 'float32' ) - [] - - -{{alias}}( length[, dtype] ) - Returns an uninitialized typed array having a specified length from a typed - array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > arr = {{alias}}( 5, 'int32' ) - - - -{{alias}}( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - This method shares the same security vulnerabilities mentioned above. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc() - - > arr = {{alias}}.malloc( 'float32' ) - - - -{{alias}}.malloc( length[, dtype] ) - Returns a typed array having a specified length from a typed array memory - pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc( 5 ) - - > arr = {{alias}}.malloc( 5, 'int32' ) - - - -{{alias}}.malloc( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}.malloc( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.calloc( [dtype] ) - Returns a zero-initialized typed array from a typed array memory pool. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc() - [] - > arr = {{alias}}.calloc( 'float32' ) - [] - - -{{alias}}.calloc( length[, dtype] ) - Returns a zero-initialized typed array having a specified length from a - typed array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}.calloc( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}.free( buf ) - Frees a typed array or typed array buffer for use in a future allocation. - - Parameters - ---------- - buf: TypedArray|ArrayBuffer - Typed array or typed array buffer to free. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ) - - -{{alias}}.clear() - Clears the typed array pool allowing garbage collection of previously - allocated (and currently free) array buffers. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - > {{alias}}.clear() - - -{{alias}}.highWaterMark - Read-only property returning the pool's high water mark. - - Once a high water mark is reached, typed array allocation fails. - - Examples - -------- - > {{alias}}.highWaterMark - - -{{alias}}.nbytes - Read-only property returning the total number of allocated bytes. - - The returned value is the total accumulated value. Hence, anytime a pool - must allocate a new array buffer (i.e., more memory), the pool increments - this value. - - The only time this value is decremented is when a pool is cleared. - - This behavior means that, while allocated buffers which are never freed may, - in fact, be garbage collected, they continue to count against the high water - mark limit. - - Accordingly, you should *always* free allocated buffers in order to prevent - the pool from believing that non-freed buffers are continually in use. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.nbytes - - -{{alias}}.factory( [options] ) - Creates a typed array pool. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.highWaterMark: integer (optional) - Maximum total memory (in bytes) which can be allocated. - - Returns - ------- - fcn: Function - Function for creating typed arrays from a typed array memory pool. - - Examples - -------- - > var pool = {{alias}}.factory(); - > var arr1 = pool( 3, 'float64' ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 4336c42..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,193 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-empty */ -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import typedarraypool = require( './index' ); - - -// TESTS // - -// The function returns a typed array or null... -{ - typedarraypool(); // $ExpectType TypedArrayOrNull - typedarraypool( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the function is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool( true ); // $ExpectError - typedarraypool( false ); // $ExpectError - typedarraypool( null ); // $ExpectError - typedarraypool( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized data type... -{ - typedarraypool( 4, true ); // $ExpectError - typedarraypool( 4, false ); // $ExpectError - typedarraypool( 4, null ); // $ExpectError - typedarraypool( 4, 'abc' ); // $ExpectError - typedarraypool( 4, 123 ); // $ExpectError - typedarraypool( 4, [] ); // $ExpectError - typedarraypool( 4, {} ); // $ExpectError - typedarraypool( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an incorrect number of arguments... -{ - typedarraypool( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `malloc` method which returns a typed array or null... -{ - typedarraypool.malloc(); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.malloc( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `malloc` method is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool.malloc( true ); // $ExpectError - typedarraypool.malloc( false ); // $ExpectError - typedarraypool.malloc( null ); // $ExpectError - typedarraypool.malloc( {} ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.malloc( 4, true ); // $ExpectError - typedarraypool.malloc( 4, false ); // $ExpectError - typedarraypool.malloc( 4, null ); // $ExpectError - typedarraypool.malloc( 4, 'abc' ); // $ExpectError - typedarraypool.malloc( 4, 123 ); // $ExpectError - typedarraypool.malloc( 4, [] ); // $ExpectError - typedarraypool.malloc( 4, {} ); // $ExpectError - typedarraypool.malloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided an incorrect number of arguments... -{ - typedarraypool.malloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `calloc` method which returns a typed array or null... -{ - typedarraypool.calloc(); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `calloc` method is provided a first argument which is not a number... -{ - typedarraypool.calloc( 'abc' ); // $ExpectError - typedarraypool.calloc( true ); // $ExpectError - typedarraypool.calloc( false ); // $ExpectError - typedarraypool.calloc( null ); // $ExpectError - typedarraypool.calloc( {} ); // $ExpectError - typedarraypool.calloc( [] ); // $ExpectError - typedarraypool.calloc( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.calloc( 4, true ); // $ExpectError - typedarraypool.calloc( 4, false ); // $ExpectError - typedarraypool.calloc( 4, null ); // $ExpectError - typedarraypool.calloc( 4, 'abc' ); // $ExpectError - typedarraypool.calloc( 4, 123 ); // $ExpectError - typedarraypool.calloc( 4, [] ); // $ExpectError - typedarraypool.calloc( 4, {} ); // $ExpectError - typedarraypool.calloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided an incorrect number of arguments... -{ - typedarraypool.calloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `factory` method which returns a typed array pool.. -{ - typedarraypool.factory(); // $ExpectType Pool - typedarraypool.factory( { 'highWaterMark': 556 } ); // $ExpectType Pool -} - -// The compiler throws an error if the `factory` method is provided a `highWaterMark` option which is not a number... -{ - typedarraypool.factory( { 'highWaterMark': true } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': false } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': 'abc' } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': null } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': [] } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': {} } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an incorrect number of arguments... -{ - typedarraypool.factory( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` method which returns void... -{ - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.free( arr ); // $ExpectType void -} - -// The compiler throws an error if the `free` method is provided a first argument which is neither a typed array nor array buffer... -{ - typedarraypool.free( true ); // $ExpectError - typedarraypool.free( false ); // $ExpectError - typedarraypool.free( 123 ); // $ExpectError - typedarraypool.free( 'abc' ); // $ExpectError - typedarraypool.free( null ); // $ExpectError - typedarraypool.free( {} ); // $ExpectError - typedarraypool.free( ( x: number ): number => x ); // $ExpectError -} - -// Attached to the main export is a `clear` method which returns void... -{ - typedarraypool.clear(); // $ExpectType void -} - -// The compiler throws an error if the `clear` method is provided arguments... -{ - typedarraypool.clear( {} ); // $ExpectError - typedarraypool.clear( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `highWaterMark` property... -{ - typedarraypool.highWaterMark; // $ExpectType number -} - -// Attached to the main export is a `nbytes` property... -{ - typedarraypool.nbytes; // $ExpectType number -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 24a7846..0000000 --- a/examples/index.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 randu = require( '@stdlib/random-base-randu' ); -var typedarraypool = require( './../lib' ); - -// Create a typed array pool which can allocate at most 1GB: -var typedarray = typedarraypool.factory({ - 'highWaterMark': 1e9 -}); - -// Inspect the pool: -console.log( 'Max bytes: %d', typedarray.highWaterMark ); -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Allocate an array for storing double-precision floating-point numbers: -var arr1 = typedarray( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Fill the array... -var i; -for ( i = 0; i < arr1.length; i++ ) { - arr1[ i ] = randu(); -} - -// Inspect array contents: -console.log( arr1 ); - -// Free the array: -typedarray.free( arr1 ); - -// Allocate another array similar to the previous one: -var arr2 = typedarray( 5, 'float64' ); -// returns - -// Check that we have been returned a new typed array view: -console.log( arr2 === arr1 ); -// => false - -// Inspect array contents: -console.log( arr2 ); - -// Free the array: -typedarray.free( arr2 ); - -// Allocate an initialized array: -var arr3 = typedarray.calloc( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect array contents: -console.log( arr3 ); - -// Free the array: -typedarray.free( arr3 ); - -// Clear the pool: -typedarray.clear(); - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 4254ef5..0f5442f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike, RealOrComplexTypedArray, NumericDataType as DataType } from '@stdlib/types/array'; import ArrayBuffer = require( '@stdlib/array-buffer' ); diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..dec29d3 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.2.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-setter@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/array-defaults@v0.2.1-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.2.2-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.2.1-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.2.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.2.1-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";var M={float64:8,float32:4,int16:2,int32:4,int8:1,uint16:2,uint32:4,uint8:1,uint8c:1,complex64:8,complex128:16},W=j.get("dtypes.default"),E=d("complex64"),H=d("complex128");function T(e){return e instanceof E}function L(e){return e instanceof H}function P(j){var E,H,P,V;if(P={highWaterMark:9007199254740992},arguments.length&&(V=function(e,t){return w(t)?k(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(c("01H2t","highWaterMark",e.highWaterMark)):null:new TypeError(c("01H2V",t))}(P,j),V))throw V;return H=function(e){var t,r;for(t=[],r=0;r0){for(t=u(x(e.byteLength)),t=y(H.length-1,t),r=H[t],s=0;sP.highWaterMark?null:(t=new v(e),E+=e,t)}(b(t)*M[r]))?s:new e(s,0,t)}function q(){var e,i,n,l,j,v,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:W,null===(n=d(i)))throw new TypeError(c("01H2Y",i));if(e<=0)return new n(0);if(r(arguments[0]))return Y(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,o(l)?l=h(l,0):m(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=Y(n,u,i)))return j;if(L(j)||T(j))return j.set(l),j;for(g=p(l),v=f(j),b=0;b[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '01H2Y', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = resolveGetter( arr );\n\t\t\tset = resolveSetter( out );\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '01H2r', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( '01H2s', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'highWaterMark': 1024\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '01H2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'highWaterMark' ) ) {\n\t\topts.highWaterMark = options.highWaterMark;\n\t\tif ( !isNonNegativeInteger( opts.highWaterMark ) ) {\n\t\t\treturn new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Initializes a cache for pooled typed array buffers.\n*\n* @private\n* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size\n* @returns {ArrayArray} initialized cache\n*/\nfunction pool( n ) {\n\tvar out;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < n+1; i++ ) {\n\t\tout.push( [] );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default pool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DEFAULT_DTYPE","ARRAY_DEFAULTS","get","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","options","nbytes","pool","opts","err","highWaterMark","arguments","length","isObject","hasOwnProp","isNonNegativeInteger","TypeError","format","validate","n","out","i","push","createPool","ceil","log2","setReadOnly","malloc","nargs","tmp","reinterpret128","reinterpret64","buf","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","setReadOnlyAccessor","typedarray","ctor","len","dtype","pop","ArrayBuffer","arraybuffer","ceil2","BYTES_PER_ELEMENT","set","isString","isCollection","isComplex128Array","isComplex64Array","test","resolveGetter","resolveSetter","typedarraypool","main"],"mappings":";;q+EAoDIA,EAAgBC,EAAeC,IAAK,kBACpCC,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,ECjFO,CACNE,cAAiB,kBDiFbC,UAAUC,SACdH,EEnEF,SAAmBD,EAAMH,GACxB,OAAMQ,EAAUR,GAGXS,EAAYT,EAAS,mBACzBG,EAAKE,cAAgBL,EAAQK,eACvBK,EAAsBP,EAAKE,gBACzB,IAAIM,UAAWC,EAAQ,QAAS,gBAAiBT,EAAKE,gBAGxD,KARC,IAAIM,UAAWC,EAAQ,QAASZ,GASzC,CFwDQa,CAAUV,EAAMH,GACjBI,GACJ,MAAMA,EAaR,OAVAF,EG5FD,SAAeY,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,CHmFQG,CAAYC,EAAMC,EAAMjB,EAAKE,iBACpCJ,EAAS,EAEToB,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,UA+JrB,WACC,IAAIC,EACAR,EACAS,EACAR,EAEJO,EAAQjB,UAAUC,OAEjBQ,EADc,IAAVQ,EACED,IACe,IAAVC,EACLD,EAAQhB,UAAW,IAEnBgB,EAAQhB,UAAW,GAAKA,UAAW,IAE1C,GAAa,OAARS,EASJ,IANCS,EADI1B,EAAiBiB,GACfU,EAAgBV,EAAK,GAChBnB,EAAgBmB,GACrBW,EAAeX,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAIQ,EAAIjB,OAAQS,IAC5BQ,EAAKR,GAAM,EAGb,OAAOD,CACP,IA1LDM,EAAaC,EAAQ,QAwMrB,SAAeK,GACd,IAAIb,EACAc,EACAZ,EACJ,GAAKa,EAAkBF,IAASA,EAAIG,OACnCH,EAAMA,EAAIG,YACJ,IAAMC,EAAeJ,GAC3B,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAEvC,GAAKA,EAAIK,WAAa,EAAI,CAQzB,IAPAlB,EAAImB,EAAOb,EAAMO,EAAIK,aAGrBlB,EAAIoB,EAAKhC,EAAKK,OAAO,EAAGO,GAGxBc,EAAI1B,EAAMY,GACJE,EAAI,EAAGA,EAAIY,EAAErB,OAAQS,IAC1B,GAAKY,EAAGZ,KAAQW,EACf,OAAO,EAITC,EAAEX,KAAMU,EACR,CACD,OAAO,CACP,IAjODN,EAAaC,EAAQ,SAwOrB,WACC,IAAIN,EACJ,IAAMA,EAAI,EAAGA,EAAId,EAAKK,OAAQS,IAC7Bd,EAAMc,GAAIT,OAAS,EAEpBN,EAAS,CACT,IA7ODoB,EAAaC,EAAQ,gBAAiBnB,EAAKE,eAC3C8B,EAAqBb,EAAQ,UAU7B,WACC,OAAOrB,CACP,IAVMqB,EAmDP,SAASc,EAAYC,EAAMC,EAAKC,GAC/B,IAAIZ,EACJ,OAAa,IAARW,EACG,IAAID,EAAM,GAGL,QADbV,EArCD,SAAsBb,GACrB,IAAIa,EACAX,EAMJ,OAHAA,EAAII,EAAMN,IAGDZ,EAAKK,QAAUL,EAAMc,GAAIT,OAC1BL,EAAMc,GAAIwB,MAGbvC,EAAOa,EAAIX,EAAKE,cACb,MAERsB,EAAM,IAAIc,EAAa3B,GAGvBb,GAAUa,EAEHa,EACP,CAgBMe,CAAaC,EAAOL,GAAMM,EAAmBL,KAE3CZ,EAED,IAAIU,EAAMV,EAAK,EAAGW,EACzB,CAkBD,SAAShB,IACR,IAAIC,EACAgB,EACAF,EACAxC,EACAkB,EACA8B,EACArD,EACA8C,EACAtB,EAUJ,GALCuB,GAHDhB,EAAQjB,UAAUC,SACJuC,EAAUxC,UAAWiB,EAAM,IAEhCjB,UADRiB,GAAS,GAGDjC,EAGK,QADd+C,EAAO3C,EAAO6C,IAEb,MAAM,IAAI5B,UAAWC,EAAQ,QAAS2B,IAEvC,GAAKhB,GAAS,EACb,OAAO,IAAIc,EAAM,GAGlB,GAAK3B,EAAsBJ,UAAW,IACrC,OAAO8B,EAAYC,EAAM/B,UAAW,GAAKiC,GAG1C,GAAKQ,EAAczC,UAAW,IAAQ,CAYrC,GAVAgC,GADAzC,EAAMS,UAAW,IACPC,OACLyC,EAAmBnD,GACvBA,EAAM4B,EAAgB5B,EAAK,GAChBoD,EAAkBpD,GAC7BA,EAAM6B,EAAe7B,EAAK,GACf,WAAWqD,KAAMX,KAE5BD,GAAO,GAGK,QADbvB,EAAMqB,EAAYC,EAAMC,EAAKC,IAE5B,OAAOxB,EAER,GAAKjB,EAAiBiB,IAASnB,EAAgBmB,GAE9C,OADAA,EAAI8B,IAAKhD,GACFkB,EAKR,IAFAvB,EAAM2D,EAAetD,GACrBgD,EAAMO,EAAerC,GACfC,EAAI,EAAGA,EAAIsB,EAAKtB,IACrB6B,EAAK9B,EAAKC,EAAGxB,EAAKK,EAAKmB,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,QAASN,UAAW,IACjD,CAkGF,CIrTG,IAAC+C,EAAiBtD,ICPrBsB,EAAAiC,EAAA,UAAAvD"} \ No newline at end of file diff --git a/lib/bytes_per_element.json b/lib/bytes_per_element.json deleted file mode 100644 index f97fe70..0000000 --- a/lib/bytes_per_element.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "float64": 8, - "float32": 4, - "int16": 2, - "int32": 4, - "int8": 1, - "uint16": 2, - "uint32": 4, - "uint8": 1, - "uint8c": 1, - "complex64": 8, - "complex128": 16 -} diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index a421711..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +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'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'highWaterMark': 9007199254740992 - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 3fe17ca..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,372 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var isComplex64Array = require( '@stdlib/assert-is-complex64array' ); -var isComplex128Array = require( '@stdlib/assert-is-complex128array' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var ctors = require( '@stdlib/array-typed-ctors' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var resolveSetter = require( '@stdlib/array-base-resolve-setter' ); -var ARRAY_DEFAULTS = require( '@stdlib/array-defaults' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil = require( '@stdlib/math-base-special-ceil' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); -var log2 = require( '@stdlib/math-base-special-log2' ); -var min = require( '@stdlib/math-base-special-min' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var createPool = require( './pool.js' ); -var BYTES_PER_ELEMENT = require( './bytes_per_element.json' ); - - -// VARIABLES // - -var DEFAULT_DTYPE = ARRAY_DEFAULTS.get( 'dtypes.default' ); -var Complex64Array = ctors( 'complex64' ); -var Complex128Array = ctors( 'complex128' ); - - -// FUNCTIONS // - -/** -* Tests whether an array is a single-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a single-precision complex floating-point number array -*/ -function isCmplx64Array( arr ) { - return ( arr instanceof Complex64Array ); -} - -/** -* Tests whether an array is a double-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a double-precision complex floating-point number array -*/ -function isCmplx128Array( arr ) { - return ( arr instanceof Complex128Array ); -} - - -// MAIN // - -/** -* Creates a typed array pool. -* -* @param {Options} [options] - pool options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} allocator -* -* @example -* var typedarraypool = factory(); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -function factory( options ) { - var nbytes; - var pool; - var opts; - var err; - - opts = defaults(); - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - pool = createPool( ceil( log2( opts.highWaterMark ) ) ); - nbytes = 0; - - setReadOnly( malloc, 'malloc', malloc ); // circular reference - setReadOnly( malloc, 'calloc', calloc ); - setReadOnly( malloc, 'free', free ); - setReadOnly( malloc, 'clear', clear ); - setReadOnly( malloc, 'highWaterMark', opts.highWaterMark ); - setReadOnlyAccessor( malloc, 'nbytes', getBytes ); - - return malloc; - - /** - * Returns the number of allocated bytes. - * - * @private - * @returns {NonNegativeInteger} number of allocated bytes - */ - function getBytes() { - return nbytes; - } - - /** - * Returns an array buffer. - * - * @private - * @param {NonNegativeInteger} n - number of bytes - * @returns {(ArrayBuffer|null)} array buffer or null - */ - function arraybuffer( n ) { - var buf; - var i; - - // Convert the number of bytes to an index in our pool table: - i = log2( n ); - - // If we already have an available array buffer, use it... - if ( i < pool.length && pool[ i ].length ) { - return pool[ i ].pop(); - } - // Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate... - if ( nbytes+n > opts.highWaterMark ) { - return null; - } - buf = new ArrayBuffer( n ); - - // Update the running counter of allocated bytes: - nbytes += n; - - return buf; - } - - /** - * Returns a typed array. - * - * @private - * @param {Function} ctor - typed array constructor - * @param {NonNegativeInteger} len - view length - * @param {string} dtype - data type - * @returns {(TypedArray|null)} typed array or null - */ - function typedarray( ctor, len, dtype ) { - var buf; - if ( len === 0 ) { - return new ctor( 0 ); - } - buf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] ); - if ( buf === null ) { - return buf; - } - return new ctor( buf, 0, len ); - } - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length or an array-like object - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function malloc() { - var nargs; - var dtype; - var ctor; - var arr; - var out; - var set; - var get; - var len; - var i; - - nargs = arguments.length; - if ( nargs && isString( arguments[ nargs-1 ] ) ) { - nargs -= 1; - dtype = arguments[ nargs ]; - } else { - dtype = DEFAULT_DTYPE; - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( '01H2Y', dtype ) ); - } - if ( nargs <= 0 ) { - return new ctor( 0 ); - } - // Check if provided a typed array length... - if ( isNonNegativeInteger( arguments[ 0 ] ) ) { - return typedarray( ctor, arguments[ 0 ], dtype ); - } - // Check if provided an array-like object containing data elements... - if ( isCollection( arguments[ 0 ] ) ) { - arr = arguments[ 0 ]; - len = arr.length; - if ( isComplex128Array( arr ) ) { - arr = reinterpret128( arr, 0 ); - } else if ( isComplex64Array( arr ) ) { - arr = reinterpret64( arr, 0 ); - } else if ( /^complex/.test( dtype ) ) { - // Assume we've been provided an array of interleaved real and imaginary components... - len /= 2; - } - out = typedarray( ctor, len, dtype ); - if ( out === null ) { - return out; - } - if ( isCmplx128Array( out ) || isCmplx64Array( out ) ) { - out.set( arr ); - return out; - } - // Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other "unsafe" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things... - get = resolveGetter( arr ); - set = resolveSetter( out ); - for ( i = 0; i < len; i++ ) { - set( out, i, get( arr, i ) ); - } - return out; - } - throw new TypeError( format( '01H2r', arguments[ 0 ] ) ); - } - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {NonNegativeInteger} [len=0] - array length - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function calloc() { - var nargs; - var out; - var tmp; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - out = malloc(); - } else if ( nargs === 1 ) { - out = malloc( arguments[ 0 ] ); - } else { - out = malloc( arguments[ 0 ], arguments[ 1 ] ); - } - if ( out !== null ) { - // Initialize the memory... - if ( isCmplx128Array( out ) ) { - tmp = reinterpret128( out, 0 ); - } else if ( isCmplx64Array( out ) ) { - tmp = reinterpret64( out, 0 ); - } else { - tmp = out; - } - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = 0.0; - } - } - return out; - } - - /** - * Frees a typed array or typed array buffer. - * - * ## Notes - * - * - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., "freeing" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool. - * - * @private - * @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free - * @throws {TypeError} must provide a typed array or typed array buffer - * @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed - */ - function free( buf ) { - var n; - var p; - var i; - if ( isTypedArrayLike( buf ) && buf.buffer ) { - buf = buf.buffer; - } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( '01H2s', buf ) ); - } - if ( buf.byteLength > 0 ) { - n = floor( log2( buf.byteLength ) ); - - // Prohibit "freeing" array buffers which would potentially allow users to circumvent high water mark limits: - n = min( pool.length-1, n ); - - // Ensure that we do not attempt to free the same buffer more than once... - p = pool[ n ]; - for ( i = 0; i < p.length; i++ ) { - if ( p[ i ] === buf ) { - return false; - } - } - // Add the buffer to our pool of free buffers: - p.push( buf ); - } - return true; - } - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @private - */ - function clear() { - var i; - for ( i = 0; i < pool.length; i++ ) { - pool[ i ].length = 0; - } - nbytes = 0; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6c12a4e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Typed array pool. -* -* @module @stdlib/array-pool -* -* @example -* var typedarraypool = require( '@stdlib/array-pool' ); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8f69ee3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,63 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @name typedarraypool -* @type {Function} -* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a valid array length or an array-like object -* @throws {TypeError} must provide a recognized data type -* @returns {(TypedArray|null)} typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -var typedarraypool = factory(); - - -// EXPORTS // - -module.exports = typedarraypool; diff --git a/lib/pool.js b/lib/pool.js deleted file mode 100644 index 5abd287..0000000 --- a/lib/pool.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Initializes a cache for pooled typed array buffers. -* -* @private -* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size -* @returns {ArrayArray} initialized cache -*/ -function pool( n ) { - var out; - var i; - - out = []; - for ( i = 0; i < n+1; i++ ) { - out.push( [] ); - } - return out; -} - - -// EXPORTS // - -module.exports = pool; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index da746bb..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'highWaterMark': 1024 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '01H2V', options ) ); - } - if ( hasOwnProp( options, 'highWaterMark' ) ) { - opts.highWaterMark = options.highWaterMark; - if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 243a265..ce31461 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Typed array pool.", "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,78 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-resolve-getter": "^0.2.1", - "@stdlib/array-base-resolve-setter": "^0.2.1", - "@stdlib/array-buffer": "^0.2.1", - "@stdlib/array-defaults": "^0.2.1", - "@stdlib/array-typed-ctors": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-arraybuffer": "^0.2.1", - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-complex128array": "^0.2.1", - "@stdlib/assert-is-complex64array": "^0.2.1", - "@stdlib/assert-is-nonnegative-integer": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/assert-is-string": "^0.2.1", - "@stdlib/assert-is-typed-array-like": "^0.2.1", - "@stdlib/math-base-special-ceil": "^0.2.1", - "@stdlib/math-base-special-ceil2": "^0.2.1", - "@stdlib/math-base-special-floor": "^0.2.2", - "@stdlib/math-base-special-log2": "^0.2.1", - "@stdlib/math-base-special-min": "^0.2.1", - "@stdlib/strided-base-reinterpret-complex128": "^0.2.1", - "@stdlib/strided-base-reinterpret-complex64": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.2.1", - "@stdlib/array-complex64": "^0.2.1", - "@stdlib/array-float32": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/array-int16": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/array-int8": "^0.2.1", - "@stdlib/array-uint16": "^0.2.1", - "@stdlib/array-uint32": "^0.2.1", - "@stdlib/array-uint8": "^0.2.1", - "@stdlib/array-uint8c": "^0.2.1", - "@stdlib/assert-instance-of": "^0.2.1", - "@stdlib/assert-is-complex-typed-array": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-typed-array": "^0.2.1", - "@stdlib/complex-float32": "^0.2.1", - "@stdlib/complex-float64": "^0.2.1", - "@stdlib/complex-imag": "^0.2.1", - "@stdlib/complex-imagf": "^0.2.1", - "@stdlib/complex-real": "^0.2.1", - "@stdlib/complex-realf": "^0.2.1", - "@stdlib/math-base-special-pow": "^0.2.1", - "@stdlib/random-base-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..f1b5e67 --- /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.factory.js b/test/test.factory.js deleted file mode 100644 index 396aee2..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,2240 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function (no options)', function test( t ) { - t.strictEqual( typeof factory(), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - t.strictEqual( typeof factory( {} ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided a `highWaterMark` option which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (length)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a function which returns a typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, length)', function test( t ) { - var typedarraypool = factory(); - var arr; - - arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a `malloc` method which is a circular reference', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - var buf; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the returned function is a property which returns the pool\'s high water mark', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function supports specifying a high water mark which limits the total amount of memory a pool can allocate', function test( t ) { - var typedarraypool; - var arr1; - var arr2; - - typedarraypool = factory({ - 'highWaterMark': 64 // bytes - }); - - typedarraypool.clear(); - - arr1 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr1.length, 8, 'returns expected value' ); - t.strictEqual( arr1.byteLength, 64, 'returns expected value' ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - typedarraypool.free( arr1 ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Create an array which is less than or equal to the high water mark: - arr2 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr2.length, 8, 'returns expected value' ); - t.strictEqual( arr2.byteLength, 64, 'returns expected value' ); - - typedarraypool.free( arr2 ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a property which returns the total number of accumulated bytes', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var typedarraypool; - var arrs; - var i; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 54aa5ee..0000000 --- a/test/test.js +++ /dev/null @@ -1,1797 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var typedarraypool = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -}); From f9c9b0d39990944b37d2ea3ee359ad87905aa5b3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 03:44:27 +0000 Subject: [PATCH 083/103] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 4365791..3fe17ca 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -35,7 +35,7 @@ var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); var resolveSetter = require( '@stdlib/array-base-resolve-setter' ); var ARRAY_DEFAULTS = require( '@stdlib/array-defaults' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ArrayBuffer = require( '@stdlib/array-buffer' ); var ceil = require( '@stdlib/math-base-special-ceil' ); var floor = require( '@stdlib/math-base-special-floor' ); @@ -228,7 +228,7 @@ function factory( options ) { } ctor = ctors( dtype ); if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '01H2Y', dtype ) ); } if ( nargs <= 0 ) { return new ctor( 0 ); @@ -265,7 +265,7 @@ function factory( options ) { } return out; } - throw new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) ); + throw new TypeError( format( '01H2r', arguments[ 0 ] ) ); } /** @@ -331,7 +331,7 @@ function factory( options ) { if ( isTypedArrayLike( buf ) && buf.buffer ) { buf = buf.buffer; } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) ); + throw new TypeError( format( '01H2s', buf ) ); } if ( buf.byteLength > 0 ) { n = floor( log2( buf.byteLength ) ); diff --git a/lib/validate.js b/lib/validate.js index ce54890..da746bb 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '01H2V', options ) ); } if ( hasOwnProp( options, 'highWaterMark' ) ) { opts.highWaterMark = options.highWaterMark; if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) ); + return new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) ); } } return null; diff --git a/package.json b/package.json index 4e8f97b..de25f29 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "@stdlib/math-base-special-min": "^0.2.2", "@stdlib/strided-base-reinterpret-complex128": "^0.2.1", "@stdlib/strided-base-reinterpret-complex64": "^0.2.0", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", From 05d6dd2d8a4c0d211648ce43c96d32fff95c9d0a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 09:09:07 +0000 Subject: [PATCH 084/103] Remove files --- index.d.ts | 359 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5206 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 0f5442f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,359 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike, RealOrComplexTypedArray, NumericDataType as DataType } from '@stdlib/types/array'; -import ArrayBuffer = require( '@stdlib/array-buffer' ); - -/** -* Typed array or null. -*/ -type TypedArrayOrNull = RealOrComplexTypedArray | null; - -/** -* Interface defining pool options. -*/ -interface Options { - /** - * Maximum total memory which can be allocated. - */ - highWaterMark?: number; -} - -/** -* Pool interface. -*/ -interface Pool { - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr = typedarraypool(); - * // returns [] - * - * @example - * var arr = typedarraypool( 'float32' ); - * // returns [] - */ - ( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * // Allocate an array of doubles: - * var arr = typedarraypool( 5, 'float64' ); - * // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * typedarraypool.free( arr ); - * - * @example - * var arr1 = typedarraypool( [ 0.5, 0.5, 0.5 ] ); - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * @example - * var arr1 = [ 0.5, 0.5, 0.5 ]; - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - */ - ( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc(); - * // returns [] - * - * var arr2 = typedarraypool.calloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param length - typed array length - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc( 5 ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * var arr2 = typedarraypool.calloc( 5, 'uint8' ); - * // returns [ 0, 0, 0, 0, 0 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( length: number, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc(); - * // returns [] - * - * var arr2 = typedarraypool.malloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc( 5 ); - * // returns - * - * var arr2 = typedarraypool.malloc( 5, 'uint8' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 5.0, -3.0, 2.0 ] ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr2 = typedarraypool.malloc( arr1 ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr3 = typedarraypool.malloc( arr1, 'int32' ); - * // returns [ 5, -3, 2 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * typedarraypool.free( arr3 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ] ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * var arr2 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ], 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Frees a typed array or typed array buffer for use in a future allocation. - * - * @param buf - typed array or typed array buffer to free - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array for use in a future allocation: - * typedarraypool.free( arr ); - * - * // Create another typed array: - * arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array buffer for use in a future allocation: - * typedarraypool.free( arr.buffer ); - */ - free( buf: RealOrComplexTypedArray | ArrayBuffer ): void; - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr ); - * - * // ... - * - * // Clear all freed buffers: - * typedarraypool.clear(); - */ - clear(): void; - - /** - * Read-only property returning the pool's high water mark. - * - * ## Notes - * - * - Once a high water mark is reached, typed array allocation fails. - * - * @example - * var limit = typedarraypool.highWaterMark; - * // returns - */ - readonly highWaterMark: number; - - /** - * Read-only property returning the total number of allocated bytes. - * - * @example - * var arr = typedarraypool( 5, 'float64' ); - * - * var nbytes = typedarraypool.nbytes; - * // returns - */ - readonly nbytes: number; - - /** - * Creates a typed array pool. - * - * @param options - pool options - * @param options.highWaterMark - maximum total memory which can be allocated - * @throws must provide valid options - * @returns allocator - * - * @example - * var allocator = typedarraypool.factory(); - * - * // Allocate an array of doubles: - * var arr = allocator( 5, 'float64' ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * allocator.free( arr ); - */ - factory( options?: Options ): Pool; -} - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @param arg - an array length or an array-like object -* @param dtype - data type (default: 'float64') -* @returns typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -declare var typedarraypool: Pool; - - -// EXPORTS // - -export = typedarraypool; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index dec29d3..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.2.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-setter@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/array-defaults@v0.2.1-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.2.2-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.2.1-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.2.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.2.1-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";var M={float64:8,float32:4,int16:2,int32:4,int8:1,uint16:2,uint32:4,uint8:1,uint8c:1,complex64:8,complex128:16},W=j.get("dtypes.default"),E=d("complex64"),H=d("complex128");function T(e){return e instanceof E}function L(e){return e instanceof H}function P(j){var E,H,P,V;if(P={highWaterMark:9007199254740992},arguments.length&&(V=function(e,t){return w(t)?k(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(c("01H2t","highWaterMark",e.highWaterMark)):null:new TypeError(c("01H2V",t))}(P,j),V))throw V;return H=function(e){var t,r;for(t=[],r=0;r0){for(t=u(x(e.byteLength)),t=y(H.length-1,t),r=H[t],s=0;sP.highWaterMark?null:(t=new v(e),E+=e,t)}(b(t)*M[r]))?s:new e(s,0,t)}function q(){var e,i,n,l,j,v,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:W,null===(n=d(i)))throw new TypeError(c("01H2Y",i));if(e<=0)return new n(0);if(r(arguments[0]))return Y(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,o(l)?l=h(l,0):m(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=Y(n,u,i)))return j;if(L(j)||T(j))return j.set(l),j;for(g=p(l),v=f(j),b=0;b[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '01H2Y', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = resolveGetter( arr );\n\t\t\tset = resolveSetter( out );\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '01H2r', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( '01H2s', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'highWaterMark': 1024\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '01H2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'highWaterMark' ) ) {\n\t\topts.highWaterMark = options.highWaterMark;\n\t\tif ( !isNonNegativeInteger( opts.highWaterMark ) ) {\n\t\t\treturn new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Initializes a cache for pooled typed array buffers.\n*\n* @private\n* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size\n* @returns {ArrayArray} initialized cache\n*/\nfunction pool( n ) {\n\tvar out;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < n+1; i++ ) {\n\t\tout.push( [] );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default pool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DEFAULT_DTYPE","ARRAY_DEFAULTS","get","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","options","nbytes","pool","opts","err","highWaterMark","arguments","length","isObject","hasOwnProp","isNonNegativeInteger","TypeError","format","validate","n","out","i","push","createPool","ceil","log2","setReadOnly","malloc","nargs","tmp","reinterpret128","reinterpret64","buf","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","setReadOnlyAccessor","typedarray","ctor","len","dtype","pop","ArrayBuffer","arraybuffer","ceil2","BYTES_PER_ELEMENT","set","isString","isCollection","isComplex128Array","isComplex64Array","test","resolveGetter","resolveSetter","typedarraypool","main"],"mappings":";;q+EAoDIA,EAAgBC,EAAeC,IAAK,kBACpCC,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,ECjFO,CACNE,cAAiB,kBDiFbC,UAAUC,SACdH,EEnEF,SAAmBD,EAAMH,GACxB,OAAMQ,EAAUR,GAGXS,EAAYT,EAAS,mBACzBG,EAAKE,cAAgBL,EAAQK,eACvBK,EAAsBP,EAAKE,gBACzB,IAAIM,UAAWC,EAAQ,QAAS,gBAAiBT,EAAKE,gBAGxD,KARC,IAAIM,UAAWC,EAAQ,QAASZ,GASzC,CFwDQa,CAAUV,EAAMH,GACjBI,GACJ,MAAMA,EAaR,OAVAF,EG5FD,SAAeY,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,CHmFQG,CAAYC,EAAMC,EAAMjB,EAAKE,iBACpCJ,EAAS,EAEToB,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,UA+JrB,WACC,IAAIC,EACAR,EACAS,EACAR,EAEJO,EAAQjB,UAAUC,OAEjBQ,EADc,IAAVQ,EACED,IACe,IAAVC,EACLD,EAAQhB,UAAW,IAEnBgB,EAAQhB,UAAW,GAAKA,UAAW,IAE1C,GAAa,OAARS,EASJ,IANCS,EADI1B,EAAiBiB,GACfU,EAAgBV,EAAK,GAChBnB,EAAgBmB,GACrBW,EAAeX,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAIQ,EAAIjB,OAAQS,IAC5BQ,EAAKR,GAAM,EAGb,OAAOD,CACP,IA1LDM,EAAaC,EAAQ,QAwMrB,SAAeK,GACd,IAAIb,EACAc,EACAZ,EACJ,GAAKa,EAAkBF,IAASA,EAAIG,OACnCH,EAAMA,EAAIG,YACJ,IAAMC,EAAeJ,GAC3B,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAEvC,GAAKA,EAAIK,WAAa,EAAI,CAQzB,IAPAlB,EAAImB,EAAOb,EAAMO,EAAIK,aAGrBlB,EAAIoB,EAAKhC,EAAKK,OAAO,EAAGO,GAGxBc,EAAI1B,EAAMY,GACJE,EAAI,EAAGA,EAAIY,EAAErB,OAAQS,IAC1B,GAAKY,EAAGZ,KAAQW,EACf,OAAO,EAITC,EAAEX,KAAMU,EACR,CACD,OAAO,CACP,IAjODN,EAAaC,EAAQ,SAwOrB,WACC,IAAIN,EACJ,IAAMA,EAAI,EAAGA,EAAId,EAAKK,OAAQS,IAC7Bd,EAAMc,GAAIT,OAAS,EAEpBN,EAAS,CACT,IA7ODoB,EAAaC,EAAQ,gBAAiBnB,EAAKE,eAC3C8B,EAAqBb,EAAQ,UAU7B,WACC,OAAOrB,CACP,IAVMqB,EAmDP,SAASc,EAAYC,EAAMC,EAAKC,GAC/B,IAAIZ,EACJ,OAAa,IAARW,EACG,IAAID,EAAM,GAGL,QADbV,EArCD,SAAsBb,GACrB,IAAIa,EACAX,EAMJ,OAHAA,EAAII,EAAMN,IAGDZ,EAAKK,QAAUL,EAAMc,GAAIT,OAC1BL,EAAMc,GAAIwB,MAGbvC,EAAOa,EAAIX,EAAKE,cACb,MAERsB,EAAM,IAAIc,EAAa3B,GAGvBb,GAAUa,EAEHa,EACP,CAgBMe,CAAaC,EAAOL,GAAMM,EAAmBL,KAE3CZ,EAED,IAAIU,EAAMV,EAAK,EAAGW,EACzB,CAkBD,SAAShB,IACR,IAAIC,EACAgB,EACAF,EACAxC,EACAkB,EACA8B,EACArD,EACA8C,EACAtB,EAUJ,GALCuB,GAHDhB,EAAQjB,UAAUC,SACJuC,EAAUxC,UAAWiB,EAAM,IAEhCjB,UADRiB,GAAS,GAGDjC,EAGK,QADd+C,EAAO3C,EAAO6C,IAEb,MAAM,IAAI5B,UAAWC,EAAQ,QAAS2B,IAEvC,GAAKhB,GAAS,EACb,OAAO,IAAIc,EAAM,GAGlB,GAAK3B,EAAsBJ,UAAW,IACrC,OAAO8B,EAAYC,EAAM/B,UAAW,GAAKiC,GAG1C,GAAKQ,EAAczC,UAAW,IAAQ,CAYrC,GAVAgC,GADAzC,EAAMS,UAAW,IACPC,OACLyC,EAAmBnD,GACvBA,EAAM4B,EAAgB5B,EAAK,GAChBoD,EAAkBpD,GAC7BA,EAAM6B,EAAe7B,EAAK,GACf,WAAWqD,KAAMX,KAE5BD,GAAO,GAGK,QADbvB,EAAMqB,EAAYC,EAAMC,EAAKC,IAE5B,OAAOxB,EAER,GAAKjB,EAAiBiB,IAASnB,EAAgBmB,GAE9C,OADAA,EAAI8B,IAAKhD,GACFkB,EAKR,IAFAvB,EAAM2D,EAAetD,GACrBgD,EAAMO,EAAerC,GACfC,EAAI,EAAGA,EAAIsB,EAAKtB,IACrB6B,EAAK9B,EAAKC,EAAGxB,EAAKK,EAAKmB,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,QAASN,UAAW,IACjD,CAkGF,CIrTG,IAAC+C,EAAiBtD,ICPrBsB,EAAAiC,EAAA,UAAAvD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f1b5e67..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 15e2e412ba3c848e0a1be00cba8c726df28b198f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 09:09:29 +0000 Subject: [PATCH 085/103] 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 | 45 +- SECURITY.md | 5 - benchmark/benchmark.calloc.js | 246 -- benchmark/benchmark.factory.js | 71 - benchmark/benchmark.js | 246 -- benchmark/benchmark.length.complex128.js | 102 - benchmark/benchmark.length.complex64.js | 102 - benchmark/benchmark.length.float32.js | 102 - benchmark/benchmark.length.float64.js | 102 - benchmark/benchmark.length.int16.js | 102 - benchmark/benchmark.length.int32.js | 102 - benchmark/benchmark.length.int8.js | 102 - benchmark/benchmark.length.uint16.js | 102 - benchmark/benchmark.length.uint32.js | 102 - benchmark/benchmark.length.uint8.js | 102 - benchmark/benchmark.length.uint8c.js | 102 - benchmark/benchmark.malloc.js | 246 -- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 347 -- docs/types/test.ts | 193 - examples/index.js | 80 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/bytes_per_element.json | 13 - lib/defaults.js | 42 - lib/factory.js | 372 -- lib/index.js | 56 - lib/main.js | 63 - lib/pool.js | 44 - lib/validate.js | 66 - package.json | 99 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 2240 ---------- test/test.js | 1797 -------- 62 files changed, 4871 insertions(+), 10651 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.calloc.js delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.complex128.js delete mode 100644 benchmark/benchmark.length.complex64.js delete mode 100644 benchmark/benchmark.length.float32.js delete mode 100644 benchmark/benchmark.length.float64.js delete mode 100644 benchmark/benchmark.length.int16.js delete mode 100644 benchmark/benchmark.length.int32.js delete mode 100644 benchmark/benchmark.length.int8.js delete mode 100644 benchmark/benchmark.length.uint16.js delete mode 100644 benchmark/benchmark.length.uint32.js delete mode 100644 benchmark/benchmark.length.uint8.js delete mode 100644 benchmark/benchmark.length.uint8c.js delete mode 100644 benchmark/benchmark.malloc.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/bytes_per_element.json delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/pool.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ea35f20..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/array/pool) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6f7c875..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/array/pool) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 869c4e9..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -495,7 +492,7 @@ console.log( 'nbytes: %d', typedarray.nbytes ); ## 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]. @@ -564,7 +561,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/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.calloc.js b/benchmark/benchmark.calloc.js deleted file mode 100644 index fd8f53d..0000000 --- a/benchmark/benchmark.calloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':calloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 58918bb..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = typedarray.factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:highWaterMark', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'highWaterMark': 0 - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.highWaterMark = i; - f = typedarray.factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 4310559..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.complex128.js b/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 12c6668..0000000 --- a/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex64.js b/benchmark/benchmark.length.complex64.js deleted file mode 100644 index ca2b45c..0000000 --- a/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float32.js b/benchmark/benchmark.length.float32.js deleted file mode 100644 index b3b4508..0000000 --- a/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float64.js b/benchmark/benchmark.length.float64.js deleted file mode 100644 index 5f0132d..0000000 --- a/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int16.js b/benchmark/benchmark.length.int16.js deleted file mode 100644 index 9f253cb..0000000 --- a/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int32.js b/benchmark/benchmark.length.int32.js deleted file mode 100644 index f83e795..0000000 --- a/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int8.js b/benchmark/benchmark.length.int8.js deleted file mode 100644 index 5b01174..0000000 --- a/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint16.js b/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 32b0a5d..0000000 --- a/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint32.js b/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 290b90c..0000000 --- a/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8.js b/benchmark/benchmark.length.uint8.js deleted file mode 100644 index ff7d733..0000000 --- a/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8c.js b/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index 8f0d10a..0000000 --- a/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.malloc.js b/benchmark/benchmark.malloc.js deleted file mode 100644 index 1661907..0000000 --- a/benchmark/benchmark.malloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':malloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 612de17..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/array/pool" -%% click B href "https://github.com/stdlib-js/array-pool/tree/main" -%% click C href "https://github.com/stdlib-js/array-pool/tree/production" -%% click D href "https://github.com/stdlib-js/array-pool/tree/esm" -%% click E href "https://github.com/stdlib-js/array-pool/tree/deno" -%% click F href "https://github.com/stdlib-js/array-pool/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/pool -[production-url]: https://github.com/stdlib-js/array-pool/tree/production -[deno-url]: https://github.com/stdlib-js/array-pool/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-pool/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-pool/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-pool/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-pool/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-pool/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 5160b6f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import typedarraypool from '../docs/types/index'; -export = typedarraypool; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4f5b474..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var l=function(n,i){return function(){return i||n((i={exports:{}}).exports,i),i.exports}};var M=l(function(Er,w){ -function I(){return{highWaterMark:9007199254740992}}w.exports=I -});var T=l(function(Tr,E){ -var U=require('@stdlib/assert-is-plain-object/dist'),z=require('@stdlib/assert-has-own-property/dist'),G=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,k=require('@stdlib/error-tools-fmtprodmsg/dist');function H(n,i){return U(i)?z(i,"highWaterMark")&&(n.highWaterMark=i.highWaterMark,!G(n.highWaterMark))?new TypeError(k('01H2t',"highWaterMark",n.highWaterMark)):null:new TypeError(k('01H2V',i));}E.exports=H -});var C=l(function(Wr,W){ -function J(n){var i,u;for(i=[],u=0;uv.highWaterMark?null:(e=new or(r),i+=r,e)}function d(r,e,a){var t;return e===0?new r(0):(t=j(vr(e)*mr[a]),t===null?t:new r(t,0,e))}function o(){var r,e,a,t,s,x,A,c,f;if(r=arguments.length,r&&Q(arguments[r-1])?(r-=1,e=arguments[r]):e=pr,a=y(e),a===null)throw new TypeError(m('01H2Y',e));if(r<=0)return new a(0);if(X(arguments[0]))return d(a,arguments[0],e);if(Z(arguments[0])){if(t=arguments[0],c=t.length,tr(t)?t=b(t,0):er(t)?t=P(t,0):/^complex/.test(e)&&(c/=2),s=d(a,c,e),s===null)return s;if(R(s)||L(s))return s.set(t),s;for(A=ir(t),x=nr(s),f=0;f0){for(e=lr(p(r.byteLength)),e=fr(u.length-1,e),a=u[e],t=0;t[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = resolveGetter( arr );\n\t\t\tset = resolveSetter( out );\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nmodule.exports = typedarraypool;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* var typedarraypool = require( '@stdlib/array-pool' );\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,cAAiB,gBAClB,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,eAAgB,IACzCD,EAAK,cAAgBC,EAAQ,cACxB,CAACJ,EAAsBG,EAAK,aAAc,GACvC,IAAI,UAAWF,EAAQ,2EAA4E,gBAAiBE,EAAK,aAAc,CAAE,EAG3I,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cA6BA,SAASC,EAAM,EAAI,CAClB,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAI,EAAE,EAAGA,IACrBD,EAAI,KAAM,CAAC,CAAE,EAEd,OAAOA,CACR,CAKAF,EAAO,QAAUC,IC3CjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,QAAW,EACX,QAAW,EACX,MAAS,EACT,MAAS,EACT,KAAQ,EACR,OAAU,EACV,OAAU,EACV,MAAS,EACT,OAAU,EACT,UAAa,EACb,WAAc,EAChB,ICZA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAe,QAAS,8BAA+B,EACvDC,EAAmB,QAAS,oCAAqC,EACjEC,GAAgB,QAAS,+BAAgC,EACzDC,GAAmB,QAAS,kCAAmC,EAC/DC,GAAoB,QAAS,mCAAoC,EACjEC,EAAc,QAAS,uDAAwD,EAC/EC,GAAsB,QAAS,uDAAwD,EACvFC,EAAQ,QAAS,2BAA4B,EAC7CC,EAAgB,QAAS,4CAA6C,EACtEC,EAAiB,QAAS,6CAA8C,EACxEC,GAAgB,QAAS,mCAAoC,EAC7DC,GAAgB,QAAS,mCAAoC,EAC7DC,GAAiB,QAAS,wBAAyB,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,GAAc,QAAS,sBAAuB,EAC9CC,GAAO,QAAS,gCAAiC,EACjDC,GAAQ,QAAS,iCAAkC,EACnDC,GAAQ,QAAS,iCAAkC,EACnDC,EAAO,QAAS,gCAAiC,EACjDC,GAAM,QAAS,+BAAgC,EAC/CC,GAAW,IACXC,GAAW,IACXC,GAAa,IACbC,GAAoB,IAKpBC,GAAgBZ,GAAe,IAAK,gBAAiB,EACrDa,GAAiBlB,EAAO,WAAY,EACpCmB,GAAkBnB,EAAO,YAAa,EAY1C,SAASoB,EAAgBC,EAAM,CAC9B,OAASA,aAAeH,EACzB,CASA,SAASI,EAAiBD,EAAM,CAC/B,OAASA,aAAeF,EACzB,CA6BA,SAASI,GAASC,EAAU,CAC3B,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,EAAOd,GAAS,EACX,UAAU,SACde,EAAMd,GAAUa,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAAF,EAAOX,GAAYP,GAAMG,EAAMgB,EAAK,aAAc,CAAE,CAAE,EACtDF,EAAS,EAET3B,EAAa+B,EAAQ,SAAUA,CAAO,EACtC/B,EAAa+B,EAAQ,SAAUC,CAAO,EACtChC,EAAa+B,EAAQ,OAAQE,CAAK,EAClCjC,EAAa+B,EAAQ,QAASG,CAAM,EACpClC,EAAa+B,EAAQ,gBAAiBF,EAAK,aAAc,EACzD5B,GAAqB8B,EAAQ,SAAUI,CAAS,EAEzCJ,EAQP,SAASI,GAAW,CACnB,OAAOR,CACR,CASA,SAASS,EAAaC,EAAI,CACzB,IAAIC,EACAC,EAMJ,OAHAA,EAAI1B,EAAMwB,CAAE,EAGPE,EAAIX,EAAK,QAAUA,EAAMW,CAAE,EAAE,OAC1BX,EAAMW,CAAE,EAAE,IAAI,EAGjBZ,EAAOU,EAAIR,EAAK,cACb,MAERS,EAAM,IAAI7B,GAAa4B,CAAE,EAGzBV,GAAUU,EAEHC,EACR,CAWA,SAASE,EAAYC,EAAMC,EAAKC,EAAQ,CACvC,IAAIL,EACJ,OAAKI,IAAQ,EACL,IAAID,EAAM,CAAE,GAEpBH,EAAMF,EAAaxB,GAAO8B,CAAI,EAAExB,GAAmByB,CAAM,CAAE,EACtDL,IAAQ,KACLA,EAED,IAAIG,EAAMH,EAAK,EAAGI,CAAI,EAC9B,CAkBA,SAASX,GAAS,CACjB,IAAIa,EACAD,EACAF,EACAlB,EACAsB,EACAC,EACAC,EACAL,EACAH,EAUJ,GARAK,EAAQ,UAAU,OACbA,GAASnD,EAAU,UAAWmD,EAAM,CAAE,CAAE,GAC5CA,GAAS,EACTD,EAAQ,UAAWC,CAAM,GAEzBD,EAAQxB,GAETsB,EAAOvC,EAAOyC,CAAM,EACfF,IAAS,KACb,MAAM,IAAI,UAAWjC,EAAQ,sEAAuEmC,CAAM,CAAE,EAE7G,GAAKC,GAAS,EACb,OAAO,IAAIH,EAAM,CAAE,EAGpB,GAAK/C,EAAsB,UAAW,CAAE,CAAE,EACzC,OAAO8C,EAAYC,EAAM,UAAW,CAAE,EAAGE,CAAM,EAGhD,GAAKhD,EAAc,UAAW,CAAE,CAAE,EAAI,CAYrC,GAXA4B,EAAM,UAAW,CAAE,EACnBmB,EAAMnB,EAAI,OACLxB,GAAmBwB,CAAI,EAC3BA,EAAMnB,EAAgBmB,EAAK,CAAE,EAClBzB,GAAkByB,CAAI,EACjCA,EAAMpB,EAAeoB,EAAK,CAAE,EACjB,WAAW,KAAMoB,CAAM,IAElCD,GAAO,GAERG,EAAML,EAAYC,EAAMC,EAAKC,CAAM,EAC9BE,IAAQ,KACZ,OAAOA,EAER,GAAKrB,EAAiBqB,CAAI,GAAKvB,EAAgBuB,CAAI,EAClD,OAAAA,EAAI,IAAKtB,CAAI,EACNsB,EAKR,IAFAE,EAAM1C,GAAekB,CAAI,EACzBuB,EAAMxC,GAAeuC,CAAI,EACnBN,EAAI,EAAGA,EAAIG,EAAKH,IACrBO,EAAKD,EAAKN,EAAGQ,EAAKxB,EAAKgB,CAAE,CAAE,EAE5B,OAAOM,CACR,CACA,MAAM,IAAI,UAAWrC,EAAQ,wGAAyG,UAAW,CAAE,CAAE,CAAE,CACxJ,CAgBA,SAASwB,GAAS,CACjB,IAAIY,EACAC,EACAG,EACAT,EAUJ,GARAK,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAMd,EAAO,EACFa,IAAU,EACrBC,EAAMd,EAAQ,UAAW,CAAE,CAAE,EAE7Bc,EAAMd,EAAQ,UAAW,CAAE,EAAG,UAAW,CAAE,CAAE,EAEzCc,IAAQ,KASZ,IAPKrB,EAAiBqB,CAAI,EACzBG,EAAM5C,EAAgByC,EAAK,CAAE,EAClBvB,EAAgBuB,CAAI,EAC/BG,EAAM7C,EAAe0C,EAAK,CAAE,EAE5BG,EAAMH,EAEDN,EAAI,EAAGA,EAAIS,EAAI,OAAQT,IAC5BS,EAAKT,CAAE,EAAI,EAGb,OAAOM,CACR,CAcA,SAASZ,EAAMK,EAAM,CACpB,IAAID,EACAY,EACAV,EACJ,GAAK3C,EAAkB0C,CAAI,GAAKA,EAAI,OACnCA,EAAMA,EAAI,eACC,CAACzC,GAAeyC,CAAI,EAC/B,MAAM,IAAI,UAAW9B,EAAQ,4EAA6E8B,CAAI,CAAE,EAEjH,GAAKA,EAAI,WAAa,EAAI,CAQzB,IAPAD,EAAI1B,GAAOE,EAAMyB,EAAI,UAAW,CAAE,EAGlCD,EAAIvB,GAAKc,EAAK,OAAO,EAAGS,CAAE,EAG1BY,EAAIrB,EAAMS,CAAE,EACNE,EAAI,EAAGA,EAAIU,EAAE,OAAQV,IAC1B,GAAKU,EAAGV,CAAE,IAAMD,EACf,MAAO,GAITW,EAAE,KAAMX,CAAI,CACb,CACA,MAAO,EACR,CAOA,SAASJ,GAAQ,CAChB,IAAIK,EACJ,IAAMA,EAAI,EAAGA,EAAIX,EAAK,OAAQW,IAC7BX,EAAMW,CAAE,EAAE,OAAS,EAEpBZ,EAAS,CACV,CACD,CAKAnC,EAAO,QAAUiC,KCnXjB,IAAAyB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAU,IAmCVC,GAAiBD,GAAQ,EAK7BD,EAAO,QAAUE,KCnBjB,IAAIC,GAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,GAAU,IAKdF,GAAaC,EAAM,UAAWC,EAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isNonNegativeInteger", "format", "validate", "opts", "options", "require_pool", "__commonJSMin", "exports", "module", "pool", "out", "i", "require_bytes_per_element", "__commonJSMin", "exports", "module", "require_factory", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isCollection", "isTypedArrayLike", "isArrayBuffer", "isComplex64Array", "isComplex128Array", "setReadOnly", "setReadOnlyAccessor", "ctors", "reinterpret64", "reinterpret128", "resolveGetter", "resolveSetter", "ARRAY_DEFAULTS", "format", "ArrayBuffer", "ceil", "floor", "ceil2", "log2", "min", "defaults", "validate", "createPool", "BYTES_PER_ELEMENT", "DEFAULT_DTYPE", "Complex64Array", "Complex128Array", "isCmplx64Array", "arr", "isCmplx128Array", "factory", "options", "nbytes", "pool", "opts", "err", "malloc", "calloc", "free", "clear", "getBytes", "arraybuffer", "n", "buf", "i", "typedarray", "ctor", "len", "dtype", "nargs", "out", "set", "get", "tmp", "p", "require_main", "__commonJSMin", "exports", "module", "factory", "typedarraypool", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5244595..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,347 +0,0 @@ - -{{alias}}( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - Memory is **uninitialized**, which means that the contents of a returned - typed array may contain sensitive contents. - - The function supports the following data types: - - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - The default typed array data type is `float64`. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}() - [] - > arr = {{alias}}( 'float32' ) - [] - - -{{alias}}( length[, dtype] ) - Returns an uninitialized typed array having a specified length from a typed - array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > arr = {{alias}}( 5, 'int32' ) - - - -{{alias}}( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - This method shares the same security vulnerabilities mentioned above. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc() - - > arr = {{alias}}.malloc( 'float32' ) - - - -{{alias}}.malloc( length[, dtype] ) - Returns a typed array having a specified length from a typed array memory - pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc( 5 ) - - > arr = {{alias}}.malloc( 5, 'int32' ) - - - -{{alias}}.malloc( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}.malloc( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.calloc( [dtype] ) - Returns a zero-initialized typed array from a typed array memory pool. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc() - [] - > arr = {{alias}}.calloc( 'float32' ) - [] - - -{{alias}}.calloc( length[, dtype] ) - Returns a zero-initialized typed array having a specified length from a - typed array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}.calloc( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}.free( buf ) - Frees a typed array or typed array buffer for use in a future allocation. - - Parameters - ---------- - buf: TypedArray|ArrayBuffer - Typed array or typed array buffer to free. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ) - - -{{alias}}.clear() - Clears the typed array pool allowing garbage collection of previously - allocated (and currently free) array buffers. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - > {{alias}}.clear() - - -{{alias}}.highWaterMark - Read-only property returning the pool's high water mark. - - Once a high water mark is reached, typed array allocation fails. - - Examples - -------- - > {{alias}}.highWaterMark - - -{{alias}}.nbytes - Read-only property returning the total number of allocated bytes. - - The returned value is the total accumulated value. Hence, anytime a pool - must allocate a new array buffer (i.e., more memory), the pool increments - this value. - - The only time this value is decremented is when a pool is cleared. - - This behavior means that, while allocated buffers which are never freed may, - in fact, be garbage collected, they continue to count against the high water - mark limit. - - Accordingly, you should *always* free allocated buffers in order to prevent - the pool from believing that non-freed buffers are continually in use. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.nbytes - - -{{alias}}.factory( [options] ) - Creates a typed array pool. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.highWaterMark: integer (optional) - Maximum total memory (in bytes) which can be allocated. - - Returns - ------- - fcn: Function - Function for creating typed arrays from a typed array memory pool. - - Examples - -------- - > var pool = {{alias}}.factory(); - > var arr1 = pool( 3, 'float64' ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 4336c42..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,193 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-empty */ -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import typedarraypool = require( './index' ); - - -// TESTS // - -// The function returns a typed array or null... -{ - typedarraypool(); // $ExpectType TypedArrayOrNull - typedarraypool( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the function is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool( true ); // $ExpectError - typedarraypool( false ); // $ExpectError - typedarraypool( null ); // $ExpectError - typedarraypool( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized data type... -{ - typedarraypool( 4, true ); // $ExpectError - typedarraypool( 4, false ); // $ExpectError - typedarraypool( 4, null ); // $ExpectError - typedarraypool( 4, 'abc' ); // $ExpectError - typedarraypool( 4, 123 ); // $ExpectError - typedarraypool( 4, [] ); // $ExpectError - typedarraypool( 4, {} ); // $ExpectError - typedarraypool( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an incorrect number of arguments... -{ - typedarraypool( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `malloc` method which returns a typed array or null... -{ - typedarraypool.malloc(); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.malloc( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `malloc` method is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool.malloc( true ); // $ExpectError - typedarraypool.malloc( false ); // $ExpectError - typedarraypool.malloc( null ); // $ExpectError - typedarraypool.malloc( {} ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.malloc( 4, true ); // $ExpectError - typedarraypool.malloc( 4, false ); // $ExpectError - typedarraypool.malloc( 4, null ); // $ExpectError - typedarraypool.malloc( 4, 'abc' ); // $ExpectError - typedarraypool.malloc( 4, 123 ); // $ExpectError - typedarraypool.malloc( 4, [] ); // $ExpectError - typedarraypool.malloc( 4, {} ); // $ExpectError - typedarraypool.malloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided an incorrect number of arguments... -{ - typedarraypool.malloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `calloc` method which returns a typed array or null... -{ - typedarraypool.calloc(); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `calloc` method is provided a first argument which is not a number... -{ - typedarraypool.calloc( 'abc' ); // $ExpectError - typedarraypool.calloc( true ); // $ExpectError - typedarraypool.calloc( false ); // $ExpectError - typedarraypool.calloc( null ); // $ExpectError - typedarraypool.calloc( {} ); // $ExpectError - typedarraypool.calloc( [] ); // $ExpectError - typedarraypool.calloc( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.calloc( 4, true ); // $ExpectError - typedarraypool.calloc( 4, false ); // $ExpectError - typedarraypool.calloc( 4, null ); // $ExpectError - typedarraypool.calloc( 4, 'abc' ); // $ExpectError - typedarraypool.calloc( 4, 123 ); // $ExpectError - typedarraypool.calloc( 4, [] ); // $ExpectError - typedarraypool.calloc( 4, {} ); // $ExpectError - typedarraypool.calloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided an incorrect number of arguments... -{ - typedarraypool.calloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `factory` method which returns a typed array pool.. -{ - typedarraypool.factory(); // $ExpectType Pool - typedarraypool.factory( { 'highWaterMark': 556 } ); // $ExpectType Pool -} - -// The compiler throws an error if the `factory` method is provided a `highWaterMark` option which is not a number... -{ - typedarraypool.factory( { 'highWaterMark': true } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': false } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': 'abc' } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': null } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': [] } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': {} } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an incorrect number of arguments... -{ - typedarraypool.factory( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` method which returns void... -{ - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.free( arr ); // $ExpectType void -} - -// The compiler throws an error if the `free` method is provided a first argument which is neither a typed array nor array buffer... -{ - typedarraypool.free( true ); // $ExpectError - typedarraypool.free( false ); // $ExpectError - typedarraypool.free( 123 ); // $ExpectError - typedarraypool.free( 'abc' ); // $ExpectError - typedarraypool.free( null ); // $ExpectError - typedarraypool.free( {} ); // $ExpectError - typedarraypool.free( ( x: number ): number => x ); // $ExpectError -} - -// Attached to the main export is a `clear` method which returns void... -{ - typedarraypool.clear(); // $ExpectType void -} - -// The compiler throws an error if the `clear` method is provided arguments... -{ - typedarraypool.clear( {} ); // $ExpectError - typedarraypool.clear( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `highWaterMark` property... -{ - typedarraypool.highWaterMark; // $ExpectType number -} - -// Attached to the main export is a `nbytes` property... -{ - typedarraypool.nbytes; // $ExpectType number -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 24a7846..0000000 --- a/examples/index.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 randu = require( '@stdlib/random-base-randu' ); -var typedarraypool = require( './../lib' ); - -// Create a typed array pool which can allocate at most 1GB: -var typedarray = typedarraypool.factory({ - 'highWaterMark': 1e9 -}); - -// Inspect the pool: -console.log( 'Max bytes: %d', typedarray.highWaterMark ); -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Allocate an array for storing double-precision floating-point numbers: -var arr1 = typedarray( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Fill the array... -var i; -for ( i = 0; i < arr1.length; i++ ) { - arr1[ i ] = randu(); -} - -// Inspect array contents: -console.log( arr1 ); - -// Free the array: -typedarray.free( arr1 ); - -// Allocate another array similar to the previous one: -var arr2 = typedarray( 5, 'float64' ); -// returns - -// Check that we have been returned a new typed array view: -console.log( arr2 === arr1 ); -// => false - -// Inspect array contents: -console.log( arr2 ); - -// Free the array: -typedarray.free( arr2 ); - -// Allocate an initialized array: -var arr3 = typedarray.calloc( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect array contents: -console.log( arr3 ); - -// Free the array: -typedarray.free( arr3 ); - -// Clear the pool: -typedarray.clear(); - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 4254ef5..0f5442f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike, RealOrComplexTypedArray, NumericDataType as DataType } from '@stdlib/types/array'; import ArrayBuffer = require( '@stdlib/array-buffer' ); diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c8a92a5 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.2.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-setter@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/array-defaults@v0.2.1-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.2.2-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.2.1-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.2.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.2.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";var M={float64:8,float32:4,int16:2,int32:4,int8:1,uint16:2,uint32:4,uint8:1,uint8c:1,complex64:8,complex128:16},W=j.get("dtypes.default"),E=d("complex64"),H=d("complex128");function T(e){return e instanceof E}function L(e){return e instanceof H}function P(j){var E,H,P,V;if(P={highWaterMark:9007199254740992},arguments.length&&(V=function(e,t){return w(t)?k(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(c("01H2t","highWaterMark",e.highWaterMark)):null:new TypeError(c("01H2V",t))}(P,j),V))throw V;return H=function(e){var t,r;for(t=[],r=0;r0){for(t=u(x(e.byteLength)),t=y(H.length-1,t),r=H[t],s=0;sP.highWaterMark?null:(t=new v(e),E+=e,t)}(b(t)*M[r]))?s:new e(s,0,t)}function q(){var e,i,n,l,j,v,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:W,null===(n=d(i)))throw new TypeError(c("01H2Y",i));if(e<=0)return new n(0);if(r(arguments[0]))return Y(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,o(l)?l=h(l,0):m(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=Y(n,u,i)))return j;if(L(j)||T(j))return j.set(l),j;for(g=p(l),v=f(j),b=0;b[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '01H2Y', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = resolveGetter( arr );\n\t\t\tset = resolveSetter( out );\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '01H2r', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( '01H2s', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'highWaterMark': 1024\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '01H2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'highWaterMark' ) ) {\n\t\topts.highWaterMark = options.highWaterMark;\n\t\tif ( !isNonNegativeInteger( opts.highWaterMark ) ) {\n\t\t\treturn new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Initializes a cache for pooled typed array buffers.\n*\n* @private\n* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size\n* @returns {ArrayArray} initialized cache\n*/\nfunction pool( n ) {\n\tvar out;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < n+1; i++ ) {\n\t\tout.push( [] );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default pool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DEFAULT_DTYPE","ARRAY_DEFAULTS","get","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","options","nbytes","pool","opts","err","highWaterMark","arguments","length","isObject","hasOwnProp","isNonNegativeInteger","TypeError","format","validate","n","out","i","push","createPool","ceil","log2","setReadOnly","malloc","nargs","tmp","reinterpret128","reinterpret64","buf","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","setReadOnlyAccessor","typedarray","ctor","len","dtype","pop","ArrayBuffer","arraybuffer","ceil2","BYTES_PER_ELEMENT","set","isString","isCollection","isComplex128Array","isComplex64Array","test","resolveGetter","resolveSetter","typedarraypool","main"],"mappings":";;q+EAoDIA,EAAgBC,EAAeC,IAAK,kBACpCC,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,ECjFO,CACNE,cAAiB,kBDiFbC,UAAUC,SACdH,EEnEF,SAAmBD,EAAMH,GACxB,OAAMQ,EAAUR,GAGXS,EAAYT,EAAS,mBACzBG,EAAKE,cAAgBL,EAAQK,eACvBK,EAAsBP,EAAKE,gBACzB,IAAIM,UAAWC,EAAQ,QAAS,gBAAiBT,EAAKE,gBAGxD,KARC,IAAIM,UAAWC,EAAQ,QAASZ,GASzC,CFwDQa,CAAUV,EAAMH,GACjBI,GACJ,MAAMA,EAaR,OAVAF,EG5FD,SAAeY,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,CHmFQG,CAAYC,EAAMC,EAAMjB,EAAKE,iBACpCJ,EAAS,EAEToB,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,UA+JrB,WACC,IAAIC,EACAR,EACAS,EACAR,EAEJO,EAAQjB,UAAUC,OAEjBQ,EADc,IAAVQ,EACED,IACe,IAAVC,EACLD,EAAQhB,UAAW,IAEnBgB,EAAQhB,UAAW,GAAKA,UAAW,IAE1C,GAAa,OAARS,EASJ,IANCS,EADI1B,EAAiBiB,GACfU,EAAgBV,EAAK,GAChBnB,EAAgBmB,GACrBW,EAAeX,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAIQ,EAAIjB,OAAQS,IAC5BQ,EAAKR,GAAM,EAGb,OAAOD,CACP,IA1LDM,EAAaC,EAAQ,QAwMrB,SAAeK,GACd,IAAIb,EACAc,EACAZ,EACJ,GAAKa,EAAkBF,IAASA,EAAIG,OACnCH,EAAMA,EAAIG,YACJ,IAAMC,EAAeJ,GAC3B,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAEvC,GAAKA,EAAIK,WAAa,EAAI,CAQzB,IAPAlB,EAAImB,EAAOb,EAAMO,EAAIK,aAGrBlB,EAAIoB,EAAKhC,EAAKK,OAAO,EAAGO,GAGxBc,EAAI1B,EAAMY,GACJE,EAAI,EAAGA,EAAIY,EAAErB,OAAQS,IAC1B,GAAKY,EAAGZ,KAAQW,EACf,OAAO,EAITC,EAAEX,KAAMU,EACR,CACD,OAAO,CACP,IAjODN,EAAaC,EAAQ,SAwOrB,WACC,IAAIN,EACJ,IAAMA,EAAI,EAAGA,EAAId,EAAKK,OAAQS,IAC7Bd,EAAMc,GAAIT,OAAS,EAEpBN,EAAS,CACT,IA7ODoB,EAAaC,EAAQ,gBAAiBnB,EAAKE,eAC3C8B,EAAqBb,EAAQ,UAU7B,WACC,OAAOrB,CACP,IAVMqB,EAmDP,SAASc,EAAYC,EAAMC,EAAKC,GAC/B,IAAIZ,EACJ,OAAa,IAARW,EACG,IAAID,EAAM,GAGL,QADbV,EArCD,SAAsBb,GACrB,IAAIa,EACAX,EAMJ,OAHAA,EAAII,EAAMN,IAGDZ,EAAKK,QAAUL,EAAMc,GAAIT,OAC1BL,EAAMc,GAAIwB,MAGbvC,EAAOa,EAAIX,EAAKE,cACb,MAERsB,EAAM,IAAIc,EAAa3B,GAGvBb,GAAUa,EAEHa,EACP,CAgBMe,CAAaC,EAAOL,GAAMM,EAAmBL,KAE3CZ,EAED,IAAIU,EAAMV,EAAK,EAAGW,EACzB,CAkBD,SAAShB,IACR,IAAIC,EACAgB,EACAF,EACAxC,EACAkB,EACA8B,EACArD,EACA8C,EACAtB,EAUJ,GALCuB,GAHDhB,EAAQjB,UAAUC,SACJuC,EAAUxC,UAAWiB,EAAM,IAEhCjB,UADRiB,GAAS,GAGDjC,EAGK,QADd+C,EAAO3C,EAAO6C,IAEb,MAAM,IAAI5B,UAAWC,EAAQ,QAAS2B,IAEvC,GAAKhB,GAAS,EACb,OAAO,IAAIc,EAAM,GAGlB,GAAK3B,EAAsBJ,UAAW,IACrC,OAAO8B,EAAYC,EAAM/B,UAAW,GAAKiC,GAG1C,GAAKQ,EAAczC,UAAW,IAAQ,CAYrC,GAVAgC,GADAzC,EAAMS,UAAW,IACPC,OACLyC,EAAmBnD,GACvBA,EAAM4B,EAAgB5B,EAAK,GAChBoD,EAAkBpD,GAC7BA,EAAM6B,EAAe7B,EAAK,GACf,WAAWqD,KAAMX,KAE5BD,GAAO,GAGK,QADbvB,EAAMqB,EAAYC,EAAMC,EAAKC,IAE5B,OAAOxB,EAER,GAAKjB,EAAiBiB,IAASnB,EAAgBmB,GAE9C,OADAA,EAAI8B,IAAKhD,GACFkB,EAKR,IAFAvB,EAAM2D,EAAetD,GACrBgD,EAAMO,EAAerC,GACfC,EAAI,EAAGA,EAAIsB,EAAKtB,IACrB6B,EAAK9B,EAAKC,EAAGxB,EAAKK,EAAKmB,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,QAASN,UAAW,IACjD,CAkGF,CIrTG,IAAC+C,EAAiBtD,ICPrBsB,EAAAiC,EAAA,UAAAvD"} \ No newline at end of file diff --git a/lib/bytes_per_element.json b/lib/bytes_per_element.json deleted file mode 100644 index f97fe70..0000000 --- a/lib/bytes_per_element.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "float64": 8, - "float32": 4, - "int16": 2, - "int32": 4, - "int8": 1, - "uint16": 2, - "uint32": 4, - "uint8": 1, - "uint8c": 1, - "complex64": 8, - "complex128": 16 -} diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index a421711..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +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'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'highWaterMark': 9007199254740992 - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 3fe17ca..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,372 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var isComplex64Array = require( '@stdlib/assert-is-complex64array' ); -var isComplex128Array = require( '@stdlib/assert-is-complex128array' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var ctors = require( '@stdlib/array-typed-ctors' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var resolveSetter = require( '@stdlib/array-base-resolve-setter' ); -var ARRAY_DEFAULTS = require( '@stdlib/array-defaults' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil = require( '@stdlib/math-base-special-ceil' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); -var log2 = require( '@stdlib/math-base-special-log2' ); -var min = require( '@stdlib/math-base-special-min' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var createPool = require( './pool.js' ); -var BYTES_PER_ELEMENT = require( './bytes_per_element.json' ); - - -// VARIABLES // - -var DEFAULT_DTYPE = ARRAY_DEFAULTS.get( 'dtypes.default' ); -var Complex64Array = ctors( 'complex64' ); -var Complex128Array = ctors( 'complex128' ); - - -// FUNCTIONS // - -/** -* Tests whether an array is a single-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a single-precision complex floating-point number array -*/ -function isCmplx64Array( arr ) { - return ( arr instanceof Complex64Array ); -} - -/** -* Tests whether an array is a double-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a double-precision complex floating-point number array -*/ -function isCmplx128Array( arr ) { - return ( arr instanceof Complex128Array ); -} - - -// MAIN // - -/** -* Creates a typed array pool. -* -* @param {Options} [options] - pool options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} allocator -* -* @example -* var typedarraypool = factory(); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -function factory( options ) { - var nbytes; - var pool; - var opts; - var err; - - opts = defaults(); - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - pool = createPool( ceil( log2( opts.highWaterMark ) ) ); - nbytes = 0; - - setReadOnly( malloc, 'malloc', malloc ); // circular reference - setReadOnly( malloc, 'calloc', calloc ); - setReadOnly( malloc, 'free', free ); - setReadOnly( malloc, 'clear', clear ); - setReadOnly( malloc, 'highWaterMark', opts.highWaterMark ); - setReadOnlyAccessor( malloc, 'nbytes', getBytes ); - - return malloc; - - /** - * Returns the number of allocated bytes. - * - * @private - * @returns {NonNegativeInteger} number of allocated bytes - */ - function getBytes() { - return nbytes; - } - - /** - * Returns an array buffer. - * - * @private - * @param {NonNegativeInteger} n - number of bytes - * @returns {(ArrayBuffer|null)} array buffer or null - */ - function arraybuffer( n ) { - var buf; - var i; - - // Convert the number of bytes to an index in our pool table: - i = log2( n ); - - // If we already have an available array buffer, use it... - if ( i < pool.length && pool[ i ].length ) { - return pool[ i ].pop(); - } - // Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate... - if ( nbytes+n > opts.highWaterMark ) { - return null; - } - buf = new ArrayBuffer( n ); - - // Update the running counter of allocated bytes: - nbytes += n; - - return buf; - } - - /** - * Returns a typed array. - * - * @private - * @param {Function} ctor - typed array constructor - * @param {NonNegativeInteger} len - view length - * @param {string} dtype - data type - * @returns {(TypedArray|null)} typed array or null - */ - function typedarray( ctor, len, dtype ) { - var buf; - if ( len === 0 ) { - return new ctor( 0 ); - } - buf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] ); - if ( buf === null ) { - return buf; - } - return new ctor( buf, 0, len ); - } - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length or an array-like object - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function malloc() { - var nargs; - var dtype; - var ctor; - var arr; - var out; - var set; - var get; - var len; - var i; - - nargs = arguments.length; - if ( nargs && isString( arguments[ nargs-1 ] ) ) { - nargs -= 1; - dtype = arguments[ nargs ]; - } else { - dtype = DEFAULT_DTYPE; - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( '01H2Y', dtype ) ); - } - if ( nargs <= 0 ) { - return new ctor( 0 ); - } - // Check if provided a typed array length... - if ( isNonNegativeInteger( arguments[ 0 ] ) ) { - return typedarray( ctor, arguments[ 0 ], dtype ); - } - // Check if provided an array-like object containing data elements... - if ( isCollection( arguments[ 0 ] ) ) { - arr = arguments[ 0 ]; - len = arr.length; - if ( isComplex128Array( arr ) ) { - arr = reinterpret128( arr, 0 ); - } else if ( isComplex64Array( arr ) ) { - arr = reinterpret64( arr, 0 ); - } else if ( /^complex/.test( dtype ) ) { - // Assume we've been provided an array of interleaved real and imaginary components... - len /= 2; - } - out = typedarray( ctor, len, dtype ); - if ( out === null ) { - return out; - } - if ( isCmplx128Array( out ) || isCmplx64Array( out ) ) { - out.set( arr ); - return out; - } - // Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other "unsafe" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things... - get = resolveGetter( arr ); - set = resolveSetter( out ); - for ( i = 0; i < len; i++ ) { - set( out, i, get( arr, i ) ); - } - return out; - } - throw new TypeError( format( '01H2r', arguments[ 0 ] ) ); - } - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {NonNegativeInteger} [len=0] - array length - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function calloc() { - var nargs; - var out; - var tmp; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - out = malloc(); - } else if ( nargs === 1 ) { - out = malloc( arguments[ 0 ] ); - } else { - out = malloc( arguments[ 0 ], arguments[ 1 ] ); - } - if ( out !== null ) { - // Initialize the memory... - if ( isCmplx128Array( out ) ) { - tmp = reinterpret128( out, 0 ); - } else if ( isCmplx64Array( out ) ) { - tmp = reinterpret64( out, 0 ); - } else { - tmp = out; - } - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = 0.0; - } - } - return out; - } - - /** - * Frees a typed array or typed array buffer. - * - * ## Notes - * - * - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., "freeing" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool. - * - * @private - * @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free - * @throws {TypeError} must provide a typed array or typed array buffer - * @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed - */ - function free( buf ) { - var n; - var p; - var i; - if ( isTypedArrayLike( buf ) && buf.buffer ) { - buf = buf.buffer; - } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( '01H2s', buf ) ); - } - if ( buf.byteLength > 0 ) { - n = floor( log2( buf.byteLength ) ); - - // Prohibit "freeing" array buffers which would potentially allow users to circumvent high water mark limits: - n = min( pool.length-1, n ); - - // Ensure that we do not attempt to free the same buffer more than once... - p = pool[ n ]; - for ( i = 0; i < p.length; i++ ) { - if ( p[ i ] === buf ) { - return false; - } - } - // Add the buffer to our pool of free buffers: - p.push( buf ); - } - return true; - } - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @private - */ - function clear() { - var i; - for ( i = 0; i < pool.length; i++ ) { - pool[ i ].length = 0; - } - nbytes = 0; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6c12a4e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Typed array pool. -* -* @module @stdlib/array-pool -* -* @example -* var typedarraypool = require( '@stdlib/array-pool' ); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8f69ee3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,63 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @name typedarraypool -* @type {Function} -* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a valid array length or an array-like object -* @throws {TypeError} must provide a recognized data type -* @returns {(TypedArray|null)} typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -var typedarraypool = factory(); - - -// EXPORTS // - -module.exports = typedarraypool; diff --git a/lib/pool.js b/lib/pool.js deleted file mode 100644 index 5abd287..0000000 --- a/lib/pool.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Initializes a cache for pooled typed array buffers. -* -* @private -* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size -* @returns {ArrayArray} initialized cache -*/ -function pool( n ) { - var out; - var i; - - out = []; - for ( i = 0; i < n+1; i++ ) { - out.push( [] ); - } - return out; -} - - -// EXPORTS // - -module.exports = pool; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index da746bb..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'highWaterMark': 1024 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '01H2V', options ) ); - } - if ( hasOwnProp( options, 'highWaterMark' ) ) { - opts.highWaterMark = options.highWaterMark; - if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index de25f29..ce31461 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Typed array pool.", "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,78 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-resolve-getter": "^0.2.1", - "@stdlib/array-base-resolve-setter": "^0.2.1", - "@stdlib/array-buffer": "^0.2.1", - "@stdlib/array-defaults": "^0.2.1", - "@stdlib/array-typed-ctors": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-arraybuffer": "^0.2.1", - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-complex128array": "^0.2.1", - "@stdlib/assert-is-complex64array": "^0.2.1", - "@stdlib/assert-is-nonnegative-integer": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/assert-is-string": "^0.2.1", - "@stdlib/assert-is-typed-array-like": "^0.2.1", - "@stdlib/math-base-special-ceil": "^0.2.1", - "@stdlib/math-base-special-ceil2": "^0.2.1", - "@stdlib/math-base-special-floor": "^0.2.2", - "@stdlib/math-base-special-log2": "^0.2.1", - "@stdlib/math-base-special-min": "^0.2.2", - "@stdlib/strided-base-reinterpret-complex128": "^0.2.1", - "@stdlib/strided-base-reinterpret-complex64": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.2.1", - "@stdlib/array-complex64": "^0.2.1", - "@stdlib/array-float32": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/array-int16": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/array-int8": "^0.2.1", - "@stdlib/array-uint16": "^0.2.1", - "@stdlib/array-uint32": "^0.2.1", - "@stdlib/array-uint8": "^0.2.1", - "@stdlib/array-uint8c": "^0.2.1", - "@stdlib/assert-instance-of": "^0.2.1", - "@stdlib/assert-is-complex-typed-array": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-typed-array": "^0.2.1", - "@stdlib/complex-float32": "^0.2.1", - "@stdlib/complex-float64": "^0.2.1", - "@stdlib/complex-imag": "^0.2.1", - "@stdlib/complex-imagf": "^0.2.1", - "@stdlib/complex-real": "^0.2.1", - "@stdlib/complex-realf": "^0.2.1", - "@stdlib/math-base-special-pow": "^0.2.1", - "@stdlib/random-base-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..2b69d1f --- /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.factory.js b/test/test.factory.js deleted file mode 100644 index 396aee2..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,2240 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function (no options)', function test( t ) { - t.strictEqual( typeof factory(), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - t.strictEqual( typeof factory( {} ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided a `highWaterMark` option which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (length)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a function which returns a typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, length)', function test( t ) { - var typedarraypool = factory(); - var arr; - - arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a `malloc` method which is a circular reference', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - var buf; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the returned function is a property which returns the pool\'s high water mark', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function supports specifying a high water mark which limits the total amount of memory a pool can allocate', function test( t ) { - var typedarraypool; - var arr1; - var arr2; - - typedarraypool = factory({ - 'highWaterMark': 64 // bytes - }); - - typedarraypool.clear(); - - arr1 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr1.length, 8, 'returns expected value' ); - t.strictEqual( arr1.byteLength, 64, 'returns expected value' ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - typedarraypool.free( arr1 ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Create an array which is less than or equal to the high water mark: - arr2 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr2.length, 8, 'returns expected value' ); - t.strictEqual( arr2.byteLength, 64, 'returns expected value' ); - - typedarraypool.free( arr2 ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a property which returns the total number of accumulated bytes', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var typedarraypool; - var arrs; - var i; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 54aa5ee..0000000 --- a/test/test.js +++ /dev/null @@ -1,1797 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var typedarraypool = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -}); From 53d2f9ee7e91bea6d66f9ff32bd4a6798f9ee6d9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 25 May 2024 08:55:30 +0000 Subject: [PATCH 086/103] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index 4365791..3fe17ca 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -35,7 +35,7 @@ var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); var resolveSetter = require( '@stdlib/array-base-resolve-setter' ); var ARRAY_DEFAULTS = require( '@stdlib/array-defaults' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ArrayBuffer = require( '@stdlib/array-buffer' ); var ceil = require( '@stdlib/math-base-special-ceil' ); var floor = require( '@stdlib/math-base-special-floor' ); @@ -228,7 +228,7 @@ function factory( options ) { } ctor = ctors( dtype ); if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '01H2Y', dtype ) ); } if ( nargs <= 0 ) { return new ctor( 0 ); @@ -265,7 +265,7 @@ function factory( options ) { } return out; } - throw new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) ); + throw new TypeError( format( '01H2r', arguments[ 0 ] ) ); } /** @@ -331,7 +331,7 @@ function factory( options ) { if ( isTypedArrayLike( buf ) && buf.buffer ) { buf = buf.buffer; } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) ); + throw new TypeError( format( '01H2s', buf ) ); } if ( buf.byteLength > 0 ) { n = floor( log2( buf.byteLength ) ); diff --git a/lib/validate.js b/lib/validate.js index ce54890..da746bb 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '01H2V', options ) ); } if ( hasOwnProp( options, 'highWaterMark' ) ) { opts.highWaterMark = options.highWaterMark; if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) ); + return new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) ); } } return null; diff --git a/package.json b/package.json index afde9fc..57dc4fa 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "@stdlib/math-base-special-min": "^0.2.2", "@stdlib/strided-base-reinterpret-complex128": "^0.2.1", "@stdlib/strided-base-reinterpret-complex64": "^0.2.0", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", From d356e8e87f9fa3021e6018f54b6da2ddd6b73468 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 25 May 2024 09:04:27 +0000 Subject: [PATCH 087/103] Remove files --- index.d.ts | 359 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5206 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 0f5442f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,359 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike, RealOrComplexTypedArray, NumericDataType as DataType } from '@stdlib/types/array'; -import ArrayBuffer = require( '@stdlib/array-buffer' ); - -/** -* Typed array or null. -*/ -type TypedArrayOrNull = RealOrComplexTypedArray | null; - -/** -* Interface defining pool options. -*/ -interface Options { - /** - * Maximum total memory which can be allocated. - */ - highWaterMark?: number; -} - -/** -* Pool interface. -*/ -interface Pool { - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr = typedarraypool(); - * // returns [] - * - * @example - * var arr = typedarraypool( 'float32' ); - * // returns [] - */ - ( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * // Allocate an array of doubles: - * var arr = typedarraypool( 5, 'float64' ); - * // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * typedarraypool.free( arr ); - * - * @example - * var arr1 = typedarraypool( [ 0.5, 0.5, 0.5 ] ); - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * @example - * var arr1 = [ 0.5, 0.5, 0.5 ]; - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - */ - ( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc(); - * // returns [] - * - * var arr2 = typedarraypool.calloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param length - typed array length - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc( 5 ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * var arr2 = typedarraypool.calloc( 5, 'uint8' ); - * // returns [ 0, 0, 0, 0, 0 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( length: number, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc(); - * // returns [] - * - * var arr2 = typedarraypool.malloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc( 5 ); - * // returns - * - * var arr2 = typedarraypool.malloc( 5, 'uint8' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 5.0, -3.0, 2.0 ] ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr2 = typedarraypool.malloc( arr1 ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr3 = typedarraypool.malloc( arr1, 'int32' ); - * // returns [ 5, -3, 2 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * typedarraypool.free( arr3 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ] ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * var arr2 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ], 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Frees a typed array or typed array buffer for use in a future allocation. - * - * @param buf - typed array or typed array buffer to free - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array for use in a future allocation: - * typedarraypool.free( arr ); - * - * // Create another typed array: - * arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array buffer for use in a future allocation: - * typedarraypool.free( arr.buffer ); - */ - free( buf: RealOrComplexTypedArray | ArrayBuffer ): void; - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr ); - * - * // ... - * - * // Clear all freed buffers: - * typedarraypool.clear(); - */ - clear(): void; - - /** - * Read-only property returning the pool's high water mark. - * - * ## Notes - * - * - Once a high water mark is reached, typed array allocation fails. - * - * @example - * var limit = typedarraypool.highWaterMark; - * // returns - */ - readonly highWaterMark: number; - - /** - * Read-only property returning the total number of allocated bytes. - * - * @example - * var arr = typedarraypool( 5, 'float64' ); - * - * var nbytes = typedarraypool.nbytes; - * // returns - */ - readonly nbytes: number; - - /** - * Creates a typed array pool. - * - * @param options - pool options - * @param options.highWaterMark - maximum total memory which can be allocated - * @throws must provide valid options - * @returns allocator - * - * @example - * var allocator = typedarraypool.factory(); - * - * // Allocate an array of doubles: - * var arr = allocator( 5, 'float64' ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * allocator.free( arr ); - */ - factory( options?: Options ): Pool; -} - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @param arg - an array length or an array-like object -* @param dtype - data type (default: 'float64') -* @returns typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -declare var typedarraypool: Pool; - - -// EXPORTS // - -export = typedarraypool; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c8a92a5..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.2.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-setter@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/array-defaults@v0.2.1-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.2.2-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.2.1-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.2.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.2.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";var M={float64:8,float32:4,int16:2,int32:4,int8:1,uint16:2,uint32:4,uint8:1,uint8c:1,complex64:8,complex128:16},W=j.get("dtypes.default"),E=d("complex64"),H=d("complex128");function T(e){return e instanceof E}function L(e){return e instanceof H}function P(j){var E,H,P,V;if(P={highWaterMark:9007199254740992},arguments.length&&(V=function(e,t){return w(t)?k(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(c("01H2t","highWaterMark",e.highWaterMark)):null:new TypeError(c("01H2V",t))}(P,j),V))throw V;return H=function(e){var t,r;for(t=[],r=0;r0){for(t=u(x(e.byteLength)),t=y(H.length-1,t),r=H[t],s=0;sP.highWaterMark?null:(t=new v(e),E+=e,t)}(b(t)*M[r]))?s:new e(s,0,t)}function q(){var e,i,n,l,j,v,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:W,null===(n=d(i)))throw new TypeError(c("01H2Y",i));if(e<=0)return new n(0);if(r(arguments[0]))return Y(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,o(l)?l=h(l,0):m(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=Y(n,u,i)))return j;if(L(j)||T(j))return j.set(l),j;for(g=p(l),v=f(j),b=0;b[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '01H2Y', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = resolveGetter( arr );\n\t\t\tset = resolveSetter( out );\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '01H2r', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( '01H2s', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'highWaterMark': 1024\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '01H2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'highWaterMark' ) ) {\n\t\topts.highWaterMark = options.highWaterMark;\n\t\tif ( !isNonNegativeInteger( opts.highWaterMark ) ) {\n\t\t\treturn new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Initializes a cache for pooled typed array buffers.\n*\n* @private\n* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size\n* @returns {ArrayArray} initialized cache\n*/\nfunction pool( n ) {\n\tvar out;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < n+1; i++ ) {\n\t\tout.push( [] );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default pool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DEFAULT_DTYPE","ARRAY_DEFAULTS","get","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","options","nbytes","pool","opts","err","highWaterMark","arguments","length","isObject","hasOwnProp","isNonNegativeInteger","TypeError","format","validate","n","out","i","push","createPool","ceil","log2","setReadOnly","malloc","nargs","tmp","reinterpret128","reinterpret64","buf","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","setReadOnlyAccessor","typedarray","ctor","len","dtype","pop","ArrayBuffer","arraybuffer","ceil2","BYTES_PER_ELEMENT","set","isString","isCollection","isComplex128Array","isComplex64Array","test","resolveGetter","resolveSetter","typedarraypool","main"],"mappings":";;q+EAoDIA,EAAgBC,EAAeC,IAAK,kBACpCC,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,ECjFO,CACNE,cAAiB,kBDiFbC,UAAUC,SACdH,EEnEF,SAAmBD,EAAMH,GACxB,OAAMQ,EAAUR,GAGXS,EAAYT,EAAS,mBACzBG,EAAKE,cAAgBL,EAAQK,eACvBK,EAAsBP,EAAKE,gBACzB,IAAIM,UAAWC,EAAQ,QAAS,gBAAiBT,EAAKE,gBAGxD,KARC,IAAIM,UAAWC,EAAQ,QAASZ,GASzC,CFwDQa,CAAUV,EAAMH,GACjBI,GACJ,MAAMA,EAaR,OAVAF,EG5FD,SAAeY,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,CHmFQG,CAAYC,EAAMC,EAAMjB,EAAKE,iBACpCJ,EAAS,EAEToB,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,UA+JrB,WACC,IAAIC,EACAR,EACAS,EACAR,EAEJO,EAAQjB,UAAUC,OAEjBQ,EADc,IAAVQ,EACED,IACe,IAAVC,EACLD,EAAQhB,UAAW,IAEnBgB,EAAQhB,UAAW,GAAKA,UAAW,IAE1C,GAAa,OAARS,EASJ,IANCS,EADI1B,EAAiBiB,GACfU,EAAgBV,EAAK,GAChBnB,EAAgBmB,GACrBW,EAAeX,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAIQ,EAAIjB,OAAQS,IAC5BQ,EAAKR,GAAM,EAGb,OAAOD,CACP,IA1LDM,EAAaC,EAAQ,QAwMrB,SAAeK,GACd,IAAIb,EACAc,EACAZ,EACJ,GAAKa,EAAkBF,IAASA,EAAIG,OACnCH,EAAMA,EAAIG,YACJ,IAAMC,EAAeJ,GAC3B,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAEvC,GAAKA,EAAIK,WAAa,EAAI,CAQzB,IAPAlB,EAAImB,EAAOb,EAAMO,EAAIK,aAGrBlB,EAAIoB,EAAKhC,EAAKK,OAAO,EAAGO,GAGxBc,EAAI1B,EAAMY,GACJE,EAAI,EAAGA,EAAIY,EAAErB,OAAQS,IAC1B,GAAKY,EAAGZ,KAAQW,EACf,OAAO,EAITC,EAAEX,KAAMU,EACR,CACD,OAAO,CACP,IAjODN,EAAaC,EAAQ,SAwOrB,WACC,IAAIN,EACJ,IAAMA,EAAI,EAAGA,EAAId,EAAKK,OAAQS,IAC7Bd,EAAMc,GAAIT,OAAS,EAEpBN,EAAS,CACT,IA7ODoB,EAAaC,EAAQ,gBAAiBnB,EAAKE,eAC3C8B,EAAqBb,EAAQ,UAU7B,WACC,OAAOrB,CACP,IAVMqB,EAmDP,SAASc,EAAYC,EAAMC,EAAKC,GAC/B,IAAIZ,EACJ,OAAa,IAARW,EACG,IAAID,EAAM,GAGL,QADbV,EArCD,SAAsBb,GACrB,IAAIa,EACAX,EAMJ,OAHAA,EAAII,EAAMN,IAGDZ,EAAKK,QAAUL,EAAMc,GAAIT,OAC1BL,EAAMc,GAAIwB,MAGbvC,EAAOa,EAAIX,EAAKE,cACb,MAERsB,EAAM,IAAIc,EAAa3B,GAGvBb,GAAUa,EAEHa,EACP,CAgBMe,CAAaC,EAAOL,GAAMM,EAAmBL,KAE3CZ,EAED,IAAIU,EAAMV,EAAK,EAAGW,EACzB,CAkBD,SAAShB,IACR,IAAIC,EACAgB,EACAF,EACAxC,EACAkB,EACA8B,EACArD,EACA8C,EACAtB,EAUJ,GALCuB,GAHDhB,EAAQjB,UAAUC,SACJuC,EAAUxC,UAAWiB,EAAM,IAEhCjB,UADRiB,GAAS,GAGDjC,EAGK,QADd+C,EAAO3C,EAAO6C,IAEb,MAAM,IAAI5B,UAAWC,EAAQ,QAAS2B,IAEvC,GAAKhB,GAAS,EACb,OAAO,IAAIc,EAAM,GAGlB,GAAK3B,EAAsBJ,UAAW,IACrC,OAAO8B,EAAYC,EAAM/B,UAAW,GAAKiC,GAG1C,GAAKQ,EAAczC,UAAW,IAAQ,CAYrC,GAVAgC,GADAzC,EAAMS,UAAW,IACPC,OACLyC,EAAmBnD,GACvBA,EAAM4B,EAAgB5B,EAAK,GAChBoD,EAAkBpD,GAC7BA,EAAM6B,EAAe7B,EAAK,GACf,WAAWqD,KAAMX,KAE5BD,GAAO,GAGK,QADbvB,EAAMqB,EAAYC,EAAMC,EAAKC,IAE5B,OAAOxB,EAER,GAAKjB,EAAiBiB,IAASnB,EAAgBmB,GAE9C,OADAA,EAAI8B,IAAKhD,GACFkB,EAKR,IAFAvB,EAAM2D,EAAetD,GACrBgD,EAAMO,EAAerC,GACfC,EAAI,EAAGA,EAAIsB,EAAKtB,IACrB6B,EAAK9B,EAAKC,EAAGxB,EAAKK,EAAKmB,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,QAASN,UAAW,IACjD,CAkGF,CIrTG,IAAC+C,EAAiBtD,ICPrBsB,EAAAiC,EAAA,UAAAvD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2b69d1f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 7232828c10d3422ce4533f4187d8552cb8c939b1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 25 May 2024 09:05:00 +0000 Subject: [PATCH 088/103] 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 | 248 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 45 +- SECURITY.md | 5 - benchmark/benchmark.calloc.js | 246 -- benchmark/benchmark.factory.js | 71 - benchmark/benchmark.js | 246 -- benchmark/benchmark.length.complex128.js | 102 - benchmark/benchmark.length.complex64.js | 102 - benchmark/benchmark.length.float32.js | 102 - benchmark/benchmark.length.float64.js | 102 - benchmark/benchmark.length.int16.js | 102 - benchmark/benchmark.length.int32.js | 102 - benchmark/benchmark.length.int8.js | 102 - benchmark/benchmark.length.uint16.js | 102 - benchmark/benchmark.length.uint32.js | 102 - benchmark/benchmark.length.uint8.js | 102 - benchmark/benchmark.length.uint8c.js | 102 - benchmark/benchmark.malloc.js | 246 -- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 14 - dist/index.js.map | 7 - docs/repl.txt | 347 -- docs/types/test.ts | 193 - examples/index.js | 80 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/bytes_per_element.json | 13 - lib/defaults.js | 42 - lib/factory.js | 372 -- lib/index.js | 56 - lib/main.js | 63 - lib/pool.js | 44 - lib/validate.js | 66 - package.json | 99 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 2240 ---------- test/test.js | 1797 -------- 62 files changed, 4871 insertions(+), 10658 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.calloc.js delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.complex128.js delete mode 100644 benchmark/benchmark.length.complex64.js delete mode 100644 benchmark/benchmark.length.float32.js delete mode 100644 benchmark/benchmark.length.float64.js delete mode 100644 benchmark/benchmark.length.int16.js delete mode 100644 benchmark/benchmark.length.int32.js delete mode 100644 benchmark/benchmark.length.int8.js delete mode 100644 benchmark/benchmark.length.uint16.js delete mode 100644 benchmark/benchmark.length.uint32.js delete mode 100644 benchmark/benchmark.length.uint8.js delete mode 100644 benchmark/benchmark.length.uint8c.js delete mode 100644 benchmark/benchmark.malloc.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/bytes_per_element.json delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/pool.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ea35f20..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/array/pool) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6f7c875..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/array/pool) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 869c4e9..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f92a6c5..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -495,7 +492,7 @@ console.log( 'nbytes: %d', typedarray.nbytes ); ## 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]. @@ -564,7 +561,7 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/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.calloc.js b/benchmark/benchmark.calloc.js deleted file mode 100644 index fd8f53d..0000000 --- a/benchmark/benchmark.calloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':calloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 58918bb..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = typedarray.factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:highWaterMark', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'highWaterMark': 0 - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.highWaterMark = i; - f = typedarray.factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 4310559..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.complex128.js b/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 12c6668..0000000 --- a/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex64.js b/benchmark/benchmark.length.complex64.js deleted file mode 100644 index ca2b45c..0000000 --- a/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float32.js b/benchmark/benchmark.length.float32.js deleted file mode 100644 index b3b4508..0000000 --- a/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float64.js b/benchmark/benchmark.length.float64.js deleted file mode 100644 index 5f0132d..0000000 --- a/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int16.js b/benchmark/benchmark.length.int16.js deleted file mode 100644 index 9f253cb..0000000 --- a/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int32.js b/benchmark/benchmark.length.int32.js deleted file mode 100644 index f83e795..0000000 --- a/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int8.js b/benchmark/benchmark.length.int8.js deleted file mode 100644 index 5b01174..0000000 --- a/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint16.js b/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 32b0a5d..0000000 --- a/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint32.js b/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 290b90c..0000000 --- a/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8.js b/benchmark/benchmark.length.uint8.js deleted file mode 100644 index ff7d733..0000000 --- a/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8c.js b/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index 8f0d10a..0000000 --- a/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.malloc.js b/benchmark/benchmark.malloc.js deleted file mode 100644 index 1661907..0000000 --- a/benchmark/benchmark.malloc.js +++ /dev/null @@ -1,246 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':malloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 612de17..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/array/pool" -%% click B href "https://github.com/stdlib-js/array-pool/tree/main" -%% click C href "https://github.com/stdlib-js/array-pool/tree/production" -%% click D href "https://github.com/stdlib-js/array-pool/tree/esm" -%% click E href "https://github.com/stdlib-js/array-pool/tree/deno" -%% click F href "https://github.com/stdlib-js/array-pool/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/pool -[production-url]: https://github.com/stdlib-js/array-pool/tree/production -[deno-url]: https://github.com/stdlib-js/array-pool/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-pool/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-pool/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-pool/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-pool/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-pool/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 5160b6f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import typedarraypool from '../docs/types/index'; -export = typedarraypool; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4f5b474..0000000 --- a/dist/index.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict";var l=function(n,i){return function(){return i||n((i={exports:{}}).exports,i),i.exports}};var M=l(function(Er,w){ -function I(){return{highWaterMark:9007199254740992}}w.exports=I -});var T=l(function(Tr,E){ -var U=require('@stdlib/assert-is-plain-object/dist'),z=require('@stdlib/assert-has-own-property/dist'),G=require('@stdlib/assert-is-nonnegative-integer/dist').isPrimitive,k=require('@stdlib/error-tools-fmtprodmsg/dist');function H(n,i){return U(i)?z(i,"highWaterMark")&&(n.highWaterMark=i.highWaterMark,!G(n.highWaterMark))?new TypeError(k('01H2t',"highWaterMark",n.highWaterMark)):null:new TypeError(k('01H2V',i));}E.exports=H -});var C=l(function(Wr,W){ -function J(n){var i,u;for(i=[],u=0;uv.highWaterMark?null:(e=new or(r),i+=r,e)}function d(r,e,a){var t;return e===0?new r(0):(t=j(vr(e)*mr[a]),t===null?t:new r(t,0,e))}function o(){var r,e,a,t,s,x,A,c,f;if(r=arguments.length,r&&Q(arguments[r-1])?(r-=1,e=arguments[r]):e=pr,a=y(e),a===null)throw new TypeError(m('01H2Y',e));if(r<=0)return new a(0);if(X(arguments[0]))return d(a,arguments[0],e);if(Z(arguments[0])){if(t=arguments[0],c=t.length,tr(t)?t=b(t,0):er(t)?t=P(t,0):/^complex/.test(e)&&(c/=2),s=d(a,c,e),s===null)return s;if(R(s)||L(s))return s.set(t),s;for(A=ir(t),x=nr(s),f=0;f0){for(e=lr(p(r.byteLength)),e=fr(u.length-1,e),a=u[e],t=0;t[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = resolveGetter( arr );\n\t\t\tset = resolveSetter( out );\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nmodule.exports = typedarraypool;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* var typedarraypool = require( '@stdlib/array-pool' );\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,cAAiB,gBAClB,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,eAAgB,IACzCD,EAAK,cAAgBC,EAAQ,cACxB,CAACJ,EAAsBG,EAAK,aAAc,GACvC,IAAI,UAAWF,EAAQ,2EAA4E,gBAAiBE,EAAK,aAAc,CAAE,EAG3I,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cA6BA,SAASC,EAAM,EAAI,CAClB,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAI,EAAE,EAAGA,IACrBD,EAAI,KAAM,CAAC,CAAE,EAEd,OAAOA,CACR,CAKAF,EAAO,QAAUC,IC3CjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,QAAW,EACX,QAAW,EACX,MAAS,EACT,MAAS,EACT,KAAQ,EACR,OAAU,EACV,OAAU,EACV,MAAS,EACT,OAAU,EACT,UAAa,EACb,WAAc,EAChB,ICZA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAe,QAAS,8BAA+B,EACvDC,EAAmB,QAAS,oCAAqC,EACjEC,GAAgB,QAAS,+BAAgC,EACzDC,GAAmB,QAAS,kCAAmC,EAC/DC,GAAoB,QAAS,mCAAoC,EACjEC,EAAc,QAAS,uDAAwD,EAC/EC,GAAsB,QAAS,uDAAwD,EACvFC,EAAQ,QAAS,2BAA4B,EAC7CC,EAAgB,QAAS,4CAA6C,EACtEC,EAAiB,QAAS,6CAA8C,EACxEC,GAAgB,QAAS,mCAAoC,EAC7DC,GAAgB,QAAS,mCAAoC,EAC7DC,GAAiB,QAAS,wBAAyB,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,GAAc,QAAS,sBAAuB,EAC9CC,GAAO,QAAS,gCAAiC,EACjDC,GAAQ,QAAS,iCAAkC,EACnDC,GAAQ,QAAS,iCAAkC,EACnDC,EAAO,QAAS,gCAAiC,EACjDC,GAAM,QAAS,+BAAgC,EAC/CC,GAAW,IACXC,GAAW,IACXC,GAAa,IACbC,GAAoB,IAKpBC,GAAgBZ,GAAe,IAAK,gBAAiB,EACrDa,GAAiBlB,EAAO,WAAY,EACpCmB,GAAkBnB,EAAO,YAAa,EAY1C,SAASoB,EAAgBC,EAAM,CAC9B,OAASA,aAAeH,EACzB,CASA,SAASI,EAAiBD,EAAM,CAC/B,OAASA,aAAeF,EACzB,CA6BA,SAASI,GAASC,EAAU,CAC3B,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,EAAOd,GAAS,EACX,UAAU,SACde,EAAMd,GAAUa,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAAF,EAAOX,GAAYP,GAAMG,EAAMgB,EAAK,aAAc,CAAE,CAAE,EACtDF,EAAS,EAET3B,EAAa+B,EAAQ,SAAUA,CAAO,EACtC/B,EAAa+B,EAAQ,SAAUC,CAAO,EACtChC,EAAa+B,EAAQ,OAAQE,CAAK,EAClCjC,EAAa+B,EAAQ,QAASG,CAAM,EACpClC,EAAa+B,EAAQ,gBAAiBF,EAAK,aAAc,EACzD5B,GAAqB8B,EAAQ,SAAUI,CAAS,EAEzCJ,EAQP,SAASI,GAAW,CACnB,OAAOR,CACR,CASA,SAASS,EAAaC,EAAI,CACzB,IAAIC,EACAC,EAMJ,OAHAA,EAAI1B,EAAMwB,CAAE,EAGPE,EAAIX,EAAK,QAAUA,EAAMW,CAAE,EAAE,OAC1BX,EAAMW,CAAE,EAAE,IAAI,EAGjBZ,EAAOU,EAAIR,EAAK,cACb,MAERS,EAAM,IAAI7B,GAAa4B,CAAE,EAGzBV,GAAUU,EAEHC,EACR,CAWA,SAASE,EAAYC,EAAMC,EAAKC,EAAQ,CACvC,IAAIL,EACJ,OAAKI,IAAQ,EACL,IAAID,EAAM,CAAE,GAEpBH,EAAMF,EAAaxB,GAAO8B,CAAI,EAAExB,GAAmByB,CAAM,CAAE,EACtDL,IAAQ,KACLA,EAED,IAAIG,EAAMH,EAAK,EAAGI,CAAI,EAC9B,CAkBA,SAASX,GAAS,CACjB,IAAIa,EACAD,EACAF,EACAlB,EACAsB,EACAC,EACAC,EACAL,EACAH,EAUJ,GARAK,EAAQ,UAAU,OACbA,GAASnD,EAAU,UAAWmD,EAAM,CAAE,CAAE,GAC5CA,GAAS,EACTD,EAAQ,UAAWC,CAAM,GAEzBD,EAAQxB,GAETsB,EAAOvC,EAAOyC,CAAM,EACfF,IAAS,KACb,MAAM,IAAI,UAAWjC,EAAQ,sEAAuEmC,CAAM,CAAE,EAE7G,GAAKC,GAAS,EACb,OAAO,IAAIH,EAAM,CAAE,EAGpB,GAAK/C,EAAsB,UAAW,CAAE,CAAE,EACzC,OAAO8C,EAAYC,EAAM,UAAW,CAAE,EAAGE,CAAM,EAGhD,GAAKhD,EAAc,UAAW,CAAE,CAAE,EAAI,CAYrC,GAXA4B,EAAM,UAAW,CAAE,EACnBmB,EAAMnB,EAAI,OACLxB,GAAmBwB,CAAI,EAC3BA,EAAMnB,EAAgBmB,EAAK,CAAE,EAClBzB,GAAkByB,CAAI,EACjCA,EAAMpB,EAAeoB,EAAK,CAAE,EACjB,WAAW,KAAMoB,CAAM,IAElCD,GAAO,GAERG,EAAML,EAAYC,EAAMC,EAAKC,CAAM,EAC9BE,IAAQ,KACZ,OAAOA,EAER,GAAKrB,EAAiBqB,CAAI,GAAKvB,EAAgBuB,CAAI,EAClD,OAAAA,EAAI,IAAKtB,CAAI,EACNsB,EAKR,IAFAE,EAAM1C,GAAekB,CAAI,EACzBuB,EAAMxC,GAAeuC,CAAI,EACnBN,EAAI,EAAGA,EAAIG,EAAKH,IACrBO,EAAKD,EAAKN,EAAGQ,EAAKxB,EAAKgB,CAAE,CAAE,EAE5B,OAAOM,CACR,CACA,MAAM,IAAI,UAAWrC,EAAQ,wGAAyG,UAAW,CAAE,CAAE,CAAE,CACxJ,CAgBA,SAASwB,GAAS,CACjB,IAAIY,EACAC,EACAG,EACAT,EAUJ,GARAK,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAMd,EAAO,EACFa,IAAU,EACrBC,EAAMd,EAAQ,UAAW,CAAE,CAAE,EAE7Bc,EAAMd,EAAQ,UAAW,CAAE,EAAG,UAAW,CAAE,CAAE,EAEzCc,IAAQ,KASZ,IAPKrB,EAAiBqB,CAAI,EACzBG,EAAM5C,EAAgByC,EAAK,CAAE,EAClBvB,EAAgBuB,CAAI,EAC/BG,EAAM7C,EAAe0C,EAAK,CAAE,EAE5BG,EAAMH,EAEDN,EAAI,EAAGA,EAAIS,EAAI,OAAQT,IAC5BS,EAAKT,CAAE,EAAI,EAGb,OAAOM,CACR,CAcA,SAASZ,EAAMK,EAAM,CACpB,IAAID,EACAY,EACAV,EACJ,GAAK3C,EAAkB0C,CAAI,GAAKA,EAAI,OACnCA,EAAMA,EAAI,eACC,CAACzC,GAAeyC,CAAI,EAC/B,MAAM,IAAI,UAAW9B,EAAQ,4EAA6E8B,CAAI,CAAE,EAEjH,GAAKA,EAAI,WAAa,EAAI,CAQzB,IAPAD,EAAI1B,GAAOE,EAAMyB,EAAI,UAAW,CAAE,EAGlCD,EAAIvB,GAAKc,EAAK,OAAO,EAAGS,CAAE,EAG1BY,EAAIrB,EAAMS,CAAE,EACNE,EAAI,EAAGA,EAAIU,EAAE,OAAQV,IAC1B,GAAKU,EAAGV,CAAE,IAAMD,EACf,MAAO,GAITW,EAAE,KAAMX,CAAI,CACb,CACA,MAAO,EACR,CAOA,SAASJ,GAAQ,CAChB,IAAIK,EACJ,IAAMA,EAAI,EAAGA,EAAIX,EAAK,OAAQW,IAC7BX,EAAMW,CAAE,EAAE,OAAS,EAEpBZ,EAAS,CACV,CACD,CAKAnC,EAAO,QAAUiC,KCnXjB,IAAAyB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAU,IAmCVC,GAAiBD,GAAQ,EAK7BD,EAAO,QAAUE,KCnBjB,IAAIC,GAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,GAAU,IAKdF,GAAaC,EAAM,UAAWC,EAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isNonNegativeInteger", "format", "validate", "opts", "options", "require_pool", "__commonJSMin", "exports", "module", "pool", "out", "i", "require_bytes_per_element", "__commonJSMin", "exports", "module", "require_factory", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isCollection", "isTypedArrayLike", "isArrayBuffer", "isComplex64Array", "isComplex128Array", "setReadOnly", "setReadOnlyAccessor", "ctors", "reinterpret64", "reinterpret128", "resolveGetter", "resolveSetter", "ARRAY_DEFAULTS", "format", "ArrayBuffer", "ceil", "floor", "ceil2", "log2", "min", "defaults", "validate", "createPool", "BYTES_PER_ELEMENT", "DEFAULT_DTYPE", "Complex64Array", "Complex128Array", "isCmplx64Array", "arr", "isCmplx128Array", "factory", "options", "nbytes", "pool", "opts", "err", "malloc", "calloc", "free", "clear", "getBytes", "arraybuffer", "n", "buf", "i", "typedarray", "ctor", "len", "dtype", "nargs", "out", "set", "get", "tmp", "p", "require_main", "__commonJSMin", "exports", "module", "factory", "typedarraypool", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 5244595..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,347 +0,0 @@ - -{{alias}}( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - Memory is **uninitialized**, which means that the contents of a returned - typed array may contain sensitive contents. - - The function supports the following data types: - - - float64: double-precision floating-point numbers (IEEE 754) - - float32: single-precision floating-point numbers (IEEE 754) - - complex128: double-precision complex floating-point numbers - - complex64: single-precision complex floating-point numbers - - int32: 32-bit two's complement signed integers - - uint32: 32-bit unsigned integers - - int16: 16-bit two's complement signed integers - - uint16: 16-bit unsigned integers - - int8: 8-bit two's complement signed integers - - uint8: 8-bit unsigned integers - - uint8c: 8-bit unsigned integers clamped to 0-255 - - The default typed array data type is `float64`. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}() - [] - > arr = {{alias}}( 'float32' ) - [] - - -{{alias}}( length[, dtype] ) - Returns an uninitialized typed array having a specified length from a typed - array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > arr = {{alias}}( 5, 'int32' ) - - - -{{alias}}( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - This method shares the same security vulnerabilities mentioned above. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc() - - > arr = {{alias}}.malloc( 'float32' ) - - - -{{alias}}.malloc( length[, dtype] ) - Returns a typed array having a specified length from a typed array memory - pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc( 5 ) - - > arr = {{alias}}.malloc( 5, 'int32' ) - - - -{{alias}}.malloc( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}.malloc( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.calloc( [dtype] ) - Returns a zero-initialized typed array from a typed array memory pool. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc() - [] - > arr = {{alias}}.calloc( 'float32' ) - [] - - -{{alias}}.calloc( length[, dtype] ) - Returns a zero-initialized typed array having a specified length from a - typed array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}.calloc( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}.free( buf ) - Frees a typed array or typed array buffer for use in a future allocation. - - Parameters - ---------- - buf: TypedArray|ArrayBuffer - Typed array or typed array buffer to free. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ) - - -{{alias}}.clear() - Clears the typed array pool allowing garbage collection of previously - allocated (and currently free) array buffers. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - > {{alias}}.clear() - - -{{alias}}.highWaterMark - Read-only property returning the pool's high water mark. - - Once a high water mark is reached, typed array allocation fails. - - Examples - -------- - > {{alias}}.highWaterMark - - -{{alias}}.nbytes - Read-only property returning the total number of allocated bytes. - - The returned value is the total accumulated value. Hence, anytime a pool - must allocate a new array buffer (i.e., more memory), the pool increments - this value. - - The only time this value is decremented is when a pool is cleared. - - This behavior means that, while allocated buffers which are never freed may, - in fact, be garbage collected, they continue to count against the high water - mark limit. - - Accordingly, you should *always* free allocated buffers in order to prevent - the pool from believing that non-freed buffers are continually in use. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.nbytes - - -{{alias}}.factory( [options] ) - Creates a typed array pool. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.highWaterMark: integer (optional) - Maximum total memory (in bytes) which can be allocated. - - Returns - ------- - fcn: Function - Function for creating typed arrays from a typed array memory pool. - - Examples - -------- - > var pool = {{alias}}.factory(); - > var arr1 = pool( 3, 'float64' ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 4336c42..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,193 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-empty */ -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import typedarraypool = require( './index' ); - - -// TESTS // - -// The function returns a typed array or null... -{ - typedarraypool(); // $ExpectType TypedArrayOrNull - typedarraypool( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the function is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool( true ); // $ExpectError - typedarraypool( false ); // $ExpectError - typedarraypool( null ); // $ExpectError - typedarraypool( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized data type... -{ - typedarraypool( 4, true ); // $ExpectError - typedarraypool( 4, false ); // $ExpectError - typedarraypool( 4, null ); // $ExpectError - typedarraypool( 4, 'abc' ); // $ExpectError - typedarraypool( 4, 123 ); // $ExpectError - typedarraypool( 4, [] ); // $ExpectError - typedarraypool( 4, {} ); // $ExpectError - typedarraypool( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an incorrect number of arguments... -{ - typedarraypool( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `malloc` method which returns a typed array or null... -{ - typedarraypool.malloc(); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.malloc( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `malloc` method is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool.malloc( true ); // $ExpectError - typedarraypool.malloc( false ); // $ExpectError - typedarraypool.malloc( null ); // $ExpectError - typedarraypool.malloc( {} ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.malloc( 4, true ); // $ExpectError - typedarraypool.malloc( 4, false ); // $ExpectError - typedarraypool.malloc( 4, null ); // $ExpectError - typedarraypool.malloc( 4, 'abc' ); // $ExpectError - typedarraypool.malloc( 4, 123 ); // $ExpectError - typedarraypool.malloc( 4, [] ); // $ExpectError - typedarraypool.malloc( 4, {} ); // $ExpectError - typedarraypool.malloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided an incorrect number of arguments... -{ - typedarraypool.malloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `calloc` method which returns a typed array or null... -{ - typedarraypool.calloc(); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `calloc` method is provided a first argument which is not a number... -{ - typedarraypool.calloc( 'abc' ); // $ExpectError - typedarraypool.calloc( true ); // $ExpectError - typedarraypool.calloc( false ); // $ExpectError - typedarraypool.calloc( null ); // $ExpectError - typedarraypool.calloc( {} ); // $ExpectError - typedarraypool.calloc( [] ); // $ExpectError - typedarraypool.calloc( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.calloc( 4, true ); // $ExpectError - typedarraypool.calloc( 4, false ); // $ExpectError - typedarraypool.calloc( 4, null ); // $ExpectError - typedarraypool.calloc( 4, 'abc' ); // $ExpectError - typedarraypool.calloc( 4, 123 ); // $ExpectError - typedarraypool.calloc( 4, [] ); // $ExpectError - typedarraypool.calloc( 4, {} ); // $ExpectError - typedarraypool.calloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided an incorrect number of arguments... -{ - typedarraypool.calloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `factory` method which returns a typed array pool.. -{ - typedarraypool.factory(); // $ExpectType Pool - typedarraypool.factory( { 'highWaterMark': 556 } ); // $ExpectType Pool -} - -// The compiler throws an error if the `factory` method is provided a `highWaterMark` option which is not a number... -{ - typedarraypool.factory( { 'highWaterMark': true } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': false } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': 'abc' } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': null } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': [] } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': {} } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an incorrect number of arguments... -{ - typedarraypool.factory( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` method which returns void... -{ - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.free( arr ); // $ExpectType void -} - -// The compiler throws an error if the `free` method is provided a first argument which is neither a typed array nor array buffer... -{ - typedarraypool.free( true ); // $ExpectError - typedarraypool.free( false ); // $ExpectError - typedarraypool.free( 123 ); // $ExpectError - typedarraypool.free( 'abc' ); // $ExpectError - typedarraypool.free( null ); // $ExpectError - typedarraypool.free( {} ); // $ExpectError - typedarraypool.free( ( x: number ): number => x ); // $ExpectError -} - -// Attached to the main export is a `clear` method which returns void... -{ - typedarraypool.clear(); // $ExpectType void -} - -// The compiler throws an error if the `clear` method is provided arguments... -{ - typedarraypool.clear( {} ); // $ExpectError - typedarraypool.clear( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `highWaterMark` property... -{ - typedarraypool.highWaterMark; // $ExpectType number -} - -// Attached to the main export is a `nbytes` property... -{ - typedarraypool.nbytes; // $ExpectType number -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 24a7846..0000000 --- a/examples/index.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 randu = require( '@stdlib/random-base-randu' ); -var typedarraypool = require( './../lib' ); - -// Create a typed array pool which can allocate at most 1GB: -var typedarray = typedarraypool.factory({ - 'highWaterMark': 1e9 -}); - -// Inspect the pool: -console.log( 'Max bytes: %d', typedarray.highWaterMark ); -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Allocate an array for storing double-precision floating-point numbers: -var arr1 = typedarray( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Fill the array... -var i; -for ( i = 0; i < arr1.length; i++ ) { - arr1[ i ] = randu(); -} - -// Inspect array contents: -console.log( arr1 ); - -// Free the array: -typedarray.free( arr1 ); - -// Allocate another array similar to the previous one: -var arr2 = typedarray( 5, 'float64' ); -// returns - -// Check that we have been returned a new typed array view: -console.log( arr2 === arr1 ); -// => false - -// Inspect array contents: -console.log( arr2 ); - -// Free the array: -typedarray.free( arr2 ); - -// Allocate an initialized array: -var arr3 = typedarray.calloc( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect array contents: -console.log( arr3 ); - -// Free the array: -typedarray.free( arr3 ); - -// Clear the pool: -typedarray.clear(); - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 4254ef5..0f5442f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike, RealOrComplexTypedArray, NumericDataType as DataType } from '@stdlib/types/array'; import ArrayBuffer = require( '@stdlib/array-buffer' ); diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c8a92a5 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.2.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-setter@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/array-defaults@v0.2.1-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.2.2-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.2.1-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.2.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.2.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";var M={float64:8,float32:4,int16:2,int32:4,int8:1,uint16:2,uint32:4,uint8:1,uint8c:1,complex64:8,complex128:16},W=j.get("dtypes.default"),E=d("complex64"),H=d("complex128");function T(e){return e instanceof E}function L(e){return e instanceof H}function P(j){var E,H,P,V;if(P={highWaterMark:9007199254740992},arguments.length&&(V=function(e,t){return w(t)?k(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(c("01H2t","highWaterMark",e.highWaterMark)):null:new TypeError(c("01H2V",t))}(P,j),V))throw V;return H=function(e){var t,r;for(t=[],r=0;r0){for(t=u(x(e.byteLength)),t=y(H.length-1,t),r=H[t],s=0;sP.highWaterMark?null:(t=new v(e),E+=e,t)}(b(t)*M[r]))?s:new e(s,0,t)}function q(){var e,i,n,l,j,v,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:W,null===(n=d(i)))throw new TypeError(c("01H2Y",i));if(e<=0)return new n(0);if(r(arguments[0]))return Y(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,o(l)?l=h(l,0):m(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=Y(n,u,i)))return j;if(L(j)||T(j))return j.set(l),j;for(g=p(l),v=f(j),b=0;b[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '01H2Y', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = resolveGetter( arr );\n\t\t\tset = resolveSetter( out );\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '01H2r', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( '01H2s', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'highWaterMark': 1024\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '01H2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'highWaterMark' ) ) {\n\t\topts.highWaterMark = options.highWaterMark;\n\t\tif ( !isNonNegativeInteger( opts.highWaterMark ) ) {\n\t\t\treturn new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Initializes a cache for pooled typed array buffers.\n*\n* @private\n* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size\n* @returns {ArrayArray} initialized cache\n*/\nfunction pool( n ) {\n\tvar out;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < n+1; i++ ) {\n\t\tout.push( [] );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default pool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DEFAULT_DTYPE","ARRAY_DEFAULTS","get","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","options","nbytes","pool","opts","err","highWaterMark","arguments","length","isObject","hasOwnProp","isNonNegativeInteger","TypeError","format","validate","n","out","i","push","createPool","ceil","log2","setReadOnly","malloc","nargs","tmp","reinterpret128","reinterpret64","buf","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","setReadOnlyAccessor","typedarray","ctor","len","dtype","pop","ArrayBuffer","arraybuffer","ceil2","BYTES_PER_ELEMENT","set","isString","isCollection","isComplex128Array","isComplex64Array","test","resolveGetter","resolveSetter","typedarraypool","main"],"mappings":";;q+EAoDIA,EAAgBC,EAAeC,IAAK,kBACpCC,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,ECjFO,CACNE,cAAiB,kBDiFbC,UAAUC,SACdH,EEnEF,SAAmBD,EAAMH,GACxB,OAAMQ,EAAUR,GAGXS,EAAYT,EAAS,mBACzBG,EAAKE,cAAgBL,EAAQK,eACvBK,EAAsBP,EAAKE,gBACzB,IAAIM,UAAWC,EAAQ,QAAS,gBAAiBT,EAAKE,gBAGxD,KARC,IAAIM,UAAWC,EAAQ,QAASZ,GASzC,CFwDQa,CAAUV,EAAMH,GACjBI,GACJ,MAAMA,EAaR,OAVAF,EG5FD,SAAeY,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,CHmFQG,CAAYC,EAAMC,EAAMjB,EAAKE,iBACpCJ,EAAS,EAEToB,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,UA+JrB,WACC,IAAIC,EACAR,EACAS,EACAR,EAEJO,EAAQjB,UAAUC,OAEjBQ,EADc,IAAVQ,EACED,IACe,IAAVC,EACLD,EAAQhB,UAAW,IAEnBgB,EAAQhB,UAAW,GAAKA,UAAW,IAE1C,GAAa,OAARS,EASJ,IANCS,EADI1B,EAAiBiB,GACfU,EAAgBV,EAAK,GAChBnB,EAAgBmB,GACrBW,EAAeX,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAIQ,EAAIjB,OAAQS,IAC5BQ,EAAKR,GAAM,EAGb,OAAOD,CACP,IA1LDM,EAAaC,EAAQ,QAwMrB,SAAeK,GACd,IAAIb,EACAc,EACAZ,EACJ,GAAKa,EAAkBF,IAASA,EAAIG,OACnCH,EAAMA,EAAIG,YACJ,IAAMC,EAAeJ,GAC3B,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAEvC,GAAKA,EAAIK,WAAa,EAAI,CAQzB,IAPAlB,EAAImB,EAAOb,EAAMO,EAAIK,aAGrBlB,EAAIoB,EAAKhC,EAAKK,OAAO,EAAGO,GAGxBc,EAAI1B,EAAMY,GACJE,EAAI,EAAGA,EAAIY,EAAErB,OAAQS,IAC1B,GAAKY,EAAGZ,KAAQW,EACf,OAAO,EAITC,EAAEX,KAAMU,EACR,CACD,OAAO,CACP,IAjODN,EAAaC,EAAQ,SAwOrB,WACC,IAAIN,EACJ,IAAMA,EAAI,EAAGA,EAAId,EAAKK,OAAQS,IAC7Bd,EAAMc,GAAIT,OAAS,EAEpBN,EAAS,CACT,IA7ODoB,EAAaC,EAAQ,gBAAiBnB,EAAKE,eAC3C8B,EAAqBb,EAAQ,UAU7B,WACC,OAAOrB,CACP,IAVMqB,EAmDP,SAASc,EAAYC,EAAMC,EAAKC,GAC/B,IAAIZ,EACJ,OAAa,IAARW,EACG,IAAID,EAAM,GAGL,QADbV,EArCD,SAAsBb,GACrB,IAAIa,EACAX,EAMJ,OAHAA,EAAII,EAAMN,IAGDZ,EAAKK,QAAUL,EAAMc,GAAIT,OAC1BL,EAAMc,GAAIwB,MAGbvC,EAAOa,EAAIX,EAAKE,cACb,MAERsB,EAAM,IAAIc,EAAa3B,GAGvBb,GAAUa,EAEHa,EACP,CAgBMe,CAAaC,EAAOL,GAAMM,EAAmBL,KAE3CZ,EAED,IAAIU,EAAMV,EAAK,EAAGW,EACzB,CAkBD,SAAShB,IACR,IAAIC,EACAgB,EACAF,EACAxC,EACAkB,EACA8B,EACArD,EACA8C,EACAtB,EAUJ,GALCuB,GAHDhB,EAAQjB,UAAUC,SACJuC,EAAUxC,UAAWiB,EAAM,IAEhCjB,UADRiB,GAAS,GAGDjC,EAGK,QADd+C,EAAO3C,EAAO6C,IAEb,MAAM,IAAI5B,UAAWC,EAAQ,QAAS2B,IAEvC,GAAKhB,GAAS,EACb,OAAO,IAAIc,EAAM,GAGlB,GAAK3B,EAAsBJ,UAAW,IACrC,OAAO8B,EAAYC,EAAM/B,UAAW,GAAKiC,GAG1C,GAAKQ,EAAczC,UAAW,IAAQ,CAYrC,GAVAgC,GADAzC,EAAMS,UAAW,IACPC,OACLyC,EAAmBnD,GACvBA,EAAM4B,EAAgB5B,EAAK,GAChBoD,EAAkBpD,GAC7BA,EAAM6B,EAAe7B,EAAK,GACf,WAAWqD,KAAMX,KAE5BD,GAAO,GAGK,QADbvB,EAAMqB,EAAYC,EAAMC,EAAKC,IAE5B,OAAOxB,EAER,GAAKjB,EAAiBiB,IAASnB,EAAgBmB,GAE9C,OADAA,EAAI8B,IAAKhD,GACFkB,EAKR,IAFAvB,EAAM2D,EAAetD,GACrBgD,EAAMO,EAAerC,GACfC,EAAI,EAAGA,EAAIsB,EAAKtB,IACrB6B,EAAK9B,EAAKC,EAAGxB,EAAKK,EAAKmB,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,QAASN,UAAW,IACjD,CAkGF,CIrTG,IAAC+C,EAAiBtD,ICPrBsB,EAAAiC,EAAA,UAAAvD"} \ No newline at end of file diff --git a/lib/bytes_per_element.json b/lib/bytes_per_element.json deleted file mode 100644 index f97fe70..0000000 --- a/lib/bytes_per_element.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "float64": 8, - "float32": 4, - "int16": 2, - "int32": 4, - "int8": 1, - "uint16": 2, - "uint32": 4, - "uint8": 1, - "uint8c": 1, - "complex64": 8, - "complex128": 16 -} diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index a421711..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +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'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'highWaterMark': 9007199254740992 - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 3fe17ca..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,372 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var isComplex64Array = require( '@stdlib/assert-is-complex64array' ); -var isComplex128Array = require( '@stdlib/assert-is-complex128array' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var ctors = require( '@stdlib/array-typed-ctors' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var resolveSetter = require( '@stdlib/array-base-resolve-setter' ); -var ARRAY_DEFAULTS = require( '@stdlib/array-defaults' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil = require( '@stdlib/math-base-special-ceil' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); -var log2 = require( '@stdlib/math-base-special-log2' ); -var min = require( '@stdlib/math-base-special-min' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var createPool = require( './pool.js' ); -var BYTES_PER_ELEMENT = require( './bytes_per_element.json' ); - - -// VARIABLES // - -var DEFAULT_DTYPE = ARRAY_DEFAULTS.get( 'dtypes.default' ); -var Complex64Array = ctors( 'complex64' ); -var Complex128Array = ctors( 'complex128' ); - - -// FUNCTIONS // - -/** -* Tests whether an array is a single-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a single-precision complex floating-point number array -*/ -function isCmplx64Array( arr ) { - return ( arr instanceof Complex64Array ); -} - -/** -* Tests whether an array is a double-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a double-precision complex floating-point number array -*/ -function isCmplx128Array( arr ) { - return ( arr instanceof Complex128Array ); -} - - -// MAIN // - -/** -* Creates a typed array pool. -* -* @param {Options} [options] - pool options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} allocator -* -* @example -* var typedarraypool = factory(); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -function factory( options ) { - var nbytes; - var pool; - var opts; - var err; - - opts = defaults(); - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - pool = createPool( ceil( log2( opts.highWaterMark ) ) ); - nbytes = 0; - - setReadOnly( malloc, 'malloc', malloc ); // circular reference - setReadOnly( malloc, 'calloc', calloc ); - setReadOnly( malloc, 'free', free ); - setReadOnly( malloc, 'clear', clear ); - setReadOnly( malloc, 'highWaterMark', opts.highWaterMark ); - setReadOnlyAccessor( malloc, 'nbytes', getBytes ); - - return malloc; - - /** - * Returns the number of allocated bytes. - * - * @private - * @returns {NonNegativeInteger} number of allocated bytes - */ - function getBytes() { - return nbytes; - } - - /** - * Returns an array buffer. - * - * @private - * @param {NonNegativeInteger} n - number of bytes - * @returns {(ArrayBuffer|null)} array buffer or null - */ - function arraybuffer( n ) { - var buf; - var i; - - // Convert the number of bytes to an index in our pool table: - i = log2( n ); - - // If we already have an available array buffer, use it... - if ( i < pool.length && pool[ i ].length ) { - return pool[ i ].pop(); - } - // Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate... - if ( nbytes+n > opts.highWaterMark ) { - return null; - } - buf = new ArrayBuffer( n ); - - // Update the running counter of allocated bytes: - nbytes += n; - - return buf; - } - - /** - * Returns a typed array. - * - * @private - * @param {Function} ctor - typed array constructor - * @param {NonNegativeInteger} len - view length - * @param {string} dtype - data type - * @returns {(TypedArray|null)} typed array or null - */ - function typedarray( ctor, len, dtype ) { - var buf; - if ( len === 0 ) { - return new ctor( 0 ); - } - buf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] ); - if ( buf === null ) { - return buf; - } - return new ctor( buf, 0, len ); - } - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length or an array-like object - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function malloc() { - var nargs; - var dtype; - var ctor; - var arr; - var out; - var set; - var get; - var len; - var i; - - nargs = arguments.length; - if ( nargs && isString( arguments[ nargs-1 ] ) ) { - nargs -= 1; - dtype = arguments[ nargs ]; - } else { - dtype = DEFAULT_DTYPE; - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( '01H2Y', dtype ) ); - } - if ( nargs <= 0 ) { - return new ctor( 0 ); - } - // Check if provided a typed array length... - if ( isNonNegativeInteger( arguments[ 0 ] ) ) { - return typedarray( ctor, arguments[ 0 ], dtype ); - } - // Check if provided an array-like object containing data elements... - if ( isCollection( arguments[ 0 ] ) ) { - arr = arguments[ 0 ]; - len = arr.length; - if ( isComplex128Array( arr ) ) { - arr = reinterpret128( arr, 0 ); - } else if ( isComplex64Array( arr ) ) { - arr = reinterpret64( arr, 0 ); - } else if ( /^complex/.test( dtype ) ) { - // Assume we've been provided an array of interleaved real and imaginary components... - len /= 2; - } - out = typedarray( ctor, len, dtype ); - if ( out === null ) { - return out; - } - if ( isCmplx128Array( out ) || isCmplx64Array( out ) ) { - out.set( arr ); - return out; - } - // Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other "unsafe" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things... - get = resolveGetter( arr ); - set = resolveSetter( out ); - for ( i = 0; i < len; i++ ) { - set( out, i, get( arr, i ) ); - } - return out; - } - throw new TypeError( format( '01H2r', arguments[ 0 ] ) ); - } - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {NonNegativeInteger} [len=0] - array length - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function calloc() { - var nargs; - var out; - var tmp; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - out = malloc(); - } else if ( nargs === 1 ) { - out = malloc( arguments[ 0 ] ); - } else { - out = malloc( arguments[ 0 ], arguments[ 1 ] ); - } - if ( out !== null ) { - // Initialize the memory... - if ( isCmplx128Array( out ) ) { - tmp = reinterpret128( out, 0 ); - } else if ( isCmplx64Array( out ) ) { - tmp = reinterpret64( out, 0 ); - } else { - tmp = out; - } - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = 0.0; - } - } - return out; - } - - /** - * Frees a typed array or typed array buffer. - * - * ## Notes - * - * - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., "freeing" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool. - * - * @private - * @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free - * @throws {TypeError} must provide a typed array or typed array buffer - * @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed - */ - function free( buf ) { - var n; - var p; - var i; - if ( isTypedArrayLike( buf ) && buf.buffer ) { - buf = buf.buffer; - } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( '01H2s', buf ) ); - } - if ( buf.byteLength > 0 ) { - n = floor( log2( buf.byteLength ) ); - - // Prohibit "freeing" array buffers which would potentially allow users to circumvent high water mark limits: - n = min( pool.length-1, n ); - - // Ensure that we do not attempt to free the same buffer more than once... - p = pool[ n ]; - for ( i = 0; i < p.length; i++ ) { - if ( p[ i ] === buf ) { - return false; - } - } - // Add the buffer to our pool of free buffers: - p.push( buf ); - } - return true; - } - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @private - */ - function clear() { - var i; - for ( i = 0; i < pool.length; i++ ) { - pool[ i ].length = 0; - } - nbytes = 0; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6c12a4e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Typed array pool. -* -* @module @stdlib/array-pool -* -* @example -* var typedarraypool = require( '@stdlib/array-pool' ); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8f69ee3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,63 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @name typedarraypool -* @type {Function} -* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a valid array length or an array-like object -* @throws {TypeError} must provide a recognized data type -* @returns {(TypedArray|null)} typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -var typedarraypool = factory(); - - -// EXPORTS // - -module.exports = typedarraypool; diff --git a/lib/pool.js b/lib/pool.js deleted file mode 100644 index 5abd287..0000000 --- a/lib/pool.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Initializes a cache for pooled typed array buffers. -* -* @private -* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size -* @returns {ArrayArray} initialized cache -*/ -function pool( n ) { - var out; - var i; - - out = []; - for ( i = 0; i < n+1; i++ ) { - out.push( [] ); - } - return out; -} - - -// EXPORTS // - -module.exports = pool; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index da746bb..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'highWaterMark': 1024 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '01H2V', options ) ); - } - if ( hasOwnProp( options, 'highWaterMark' ) ) { - opts.highWaterMark = options.highWaterMark; - if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 57dc4fa..ce31461 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Typed array pool.", "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,78 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-resolve-getter": "^0.2.1", - "@stdlib/array-base-resolve-setter": "^0.2.1", - "@stdlib/array-buffer": "^0.2.1", - "@stdlib/array-defaults": "^0.2.1", - "@stdlib/array-typed-ctors": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-arraybuffer": "^0.2.1", - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-complex128array": "^0.2.1", - "@stdlib/assert-is-complex64array": "^0.2.1", - "@stdlib/assert-is-nonnegative-integer": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/assert-is-string": "^0.2.1", - "@stdlib/assert-is-typed-array-like": "^0.2.1", - "@stdlib/math-base-special-ceil": "^0.2.1", - "@stdlib/math-base-special-ceil2": "^0.2.1", - "@stdlib/math-base-special-floor": "^0.2.2", - "@stdlib/math-base-special-log2": "^0.2.1", - "@stdlib/math-base-special-min": "^0.2.2", - "@stdlib/strided-base-reinterpret-complex128": "^0.2.1", - "@stdlib/strided-base-reinterpret-complex64": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-complex128": "^0.2.1", - "@stdlib/array-complex64": "^0.2.1", - "@stdlib/array-float32": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/array-int16": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/array-int8": "^0.2.1", - "@stdlib/array-uint16": "^0.2.1", - "@stdlib/array-uint32": "^0.2.1", - "@stdlib/array-uint8": "^0.2.1", - "@stdlib/array-uint8c": "^0.2.1", - "@stdlib/assert-instance-of": "^0.2.1", - "@stdlib/assert-is-complex-typed-array": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-typed-array": "^0.2.1", - "@stdlib/complex-float32-ctor": "github:stdlib-js/complex-float32-ctor#main", - "@stdlib/complex-float64-ctor": "github:stdlib-js/complex-float64-ctor#main", - "@stdlib/complex-imag": "^0.2.1", - "@stdlib/complex-imagf": "^0.2.1", - "@stdlib/complex-real": "^0.2.1", - "@stdlib/complex-realf": "^0.2.1", - "@stdlib/math-base-special-pow": "^0.2.1", - "@stdlib/random-base-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..2b69d1f --- /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.factory.js b/test/test.factory.js deleted file mode 100644 index 49c1670..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,2240 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function (no options)', function test( t ) { - t.strictEqual( typeof factory(), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - t.strictEqual( typeof factory( {} ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided a `highWaterMark` option which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (length)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a function which returns a typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, length)', function test( t ) { - var typedarraypool = factory(); - var arr; - - arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a `malloc` method which is a circular reference', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - var buf; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the returned function is a property which returns the pool\'s high water mark', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function supports specifying a high water mark which limits the total amount of memory a pool can allocate', function test( t ) { - var typedarraypool; - var arr1; - var arr2; - - typedarraypool = factory({ - 'highWaterMark': 64 // bytes - }); - - typedarraypool.clear(); - - arr1 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr1.length, 8, 'returns expected value' ); - t.strictEqual( arr1.byteLength, 64, 'returns expected value' ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - typedarraypool.free( arr1 ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Create an array which is less than or equal to the high water mark: - arr2 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr2.length, 8, 'returns expected value' ); - t.strictEqual( arr2.byteLength, 64, 'returns expected value' ); - - typedarraypool.free( arr2 ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a property which returns the total number of accumulated bytes', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var typedarraypool; - var arrs; - var i; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 8e1e22f..0000000 --- a/test/test.js +++ /dev/null @@ -1,1797 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var typedarraypool = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -}); From 6e6e11e80bbd91583af12104ecae7b8a07766d23 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jul 2024 19:23:40 +0000 Subject: [PATCH 089/103] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index ce4ba27..7f297ce 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -38,7 +38,7 @@ var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); var resolveSetter = require( '@stdlib/array-base-resolve-setter' ); var ARRAY_DEFAULTS = require( '@stdlib/array-defaults' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ArrayBuffer = require( '@stdlib/array-buffer' ); var ceil = require( '@stdlib/math-base-special-ceil' ); var floor = require( '@stdlib/math-base-special-floor' ); @@ -243,7 +243,7 @@ function factory( options ) { } ctor = ctors( dtype ); if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '01H2Y', dtype ) ); } if ( nargs <= 0 ) { return new ctor( 0 ); @@ -282,7 +282,7 @@ function factory( options ) { } return out; } - throw new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) ); + throw new TypeError( format( '01H2r', arguments[ 0 ] ) ); } /** @@ -350,7 +350,7 @@ function factory( options ) { if ( isTypedArrayLike( buf ) && buf.buffer ) { buf = buf.buffer; } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) ); + throw new TypeError( format( '01H2s', buf ) ); } if ( buf.byteLength > 0 ) { n = floor( log2( buf.byteLength ) ); diff --git a/lib/validate.js b/lib/validate.js index ce54890..da746bb 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '01H2V', options ) ); } if ( hasOwnProp( options, 'highWaterMark' ) ) { opts.highWaterMark = options.highWaterMark; if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) ); + return new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) ); } } return null; diff --git a/package.json b/package.json index c4ee0d8..994a553 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "@stdlib/strided-base-reinterpret-boolean": "^0.0.1", "@stdlib/strided-base-reinterpret-complex128": "^0.2.1", "@stdlib/strided-base-reinterpret-complex64": "^0.2.0", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", From 8679abfd79b09999f12b076c25953dfa48b22a38 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jul 2024 19:24:29 +0000 Subject: [PATCH 090/103] Remove files --- index.d.ts | 359 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5206 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 0f5442f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,359 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike, RealOrComplexTypedArray, NumericDataType as DataType } from '@stdlib/types/array'; -import ArrayBuffer = require( '@stdlib/array-buffer' ); - -/** -* Typed array or null. -*/ -type TypedArrayOrNull = RealOrComplexTypedArray | null; - -/** -* Interface defining pool options. -*/ -interface Options { - /** - * Maximum total memory which can be allocated. - */ - highWaterMark?: number; -} - -/** -* Pool interface. -*/ -interface Pool { - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr = typedarraypool(); - * // returns [] - * - * @example - * var arr = typedarraypool( 'float32' ); - * // returns [] - */ - ( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * // Allocate an array of doubles: - * var arr = typedarraypool( 5, 'float64' ); - * // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * typedarraypool.free( arr ); - * - * @example - * var arr1 = typedarraypool( [ 0.5, 0.5, 0.5 ] ); - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * @example - * var arr1 = [ 0.5, 0.5, 0.5 ]; - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - */ - ( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc(); - * // returns [] - * - * var arr2 = typedarraypool.calloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param length - typed array length - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc( 5 ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * var arr2 = typedarraypool.calloc( 5, 'uint8' ); - * // returns [ 0, 0, 0, 0, 0 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( length: number, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc(); - * // returns [] - * - * var arr2 = typedarraypool.malloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc( 5 ); - * // returns - * - * var arr2 = typedarraypool.malloc( 5, 'uint8' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 5.0, -3.0, 2.0 ] ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr2 = typedarraypool.malloc( arr1 ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr3 = typedarraypool.malloc( arr1, 'int32' ); - * // returns [ 5, -3, 2 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * typedarraypool.free( arr3 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ] ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * var arr2 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ], 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Frees a typed array or typed array buffer for use in a future allocation. - * - * @param buf - typed array or typed array buffer to free - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array for use in a future allocation: - * typedarraypool.free( arr ); - * - * // Create another typed array: - * arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array buffer for use in a future allocation: - * typedarraypool.free( arr.buffer ); - */ - free( buf: RealOrComplexTypedArray | ArrayBuffer ): void; - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr ); - * - * // ... - * - * // Clear all freed buffers: - * typedarraypool.clear(); - */ - clear(): void; - - /** - * Read-only property returning the pool's high water mark. - * - * ## Notes - * - * - Once a high water mark is reached, typed array allocation fails. - * - * @example - * var limit = typedarraypool.highWaterMark; - * // returns - */ - readonly highWaterMark: number; - - /** - * Read-only property returning the total number of allocated bytes. - * - * @example - * var arr = typedarraypool( 5, 'float64' ); - * - * var nbytes = typedarraypool.nbytes; - * // returns - */ - readonly nbytes: number; - - /** - * Creates a typed array pool. - * - * @param options - pool options - * @param options.highWaterMark - maximum total memory which can be allocated - * @throws must provide valid options - * @returns allocator - * - * @example - * var allocator = typedarraypool.factory(); - * - * // Allocate an array of doubles: - * var arr = allocator( 5, 'float64' ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * allocator.free( arr ); - */ - factory( options?: Options ): Pool; -} - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @param arg - an array length or an array-like object -* @param dtype - data type (default: 'float64') -* @returns typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -declare var typedarraypool: Pool; - - -// EXPORTS // - -export = typedarraypool; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c8a92a5..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.2.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-setter@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/array-defaults@v0.2.1-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.2.2-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.2.1-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.2.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.2.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";var M={float64:8,float32:4,int16:2,int32:4,int8:1,uint16:2,uint32:4,uint8:1,uint8c:1,complex64:8,complex128:16},W=j.get("dtypes.default"),E=d("complex64"),H=d("complex128");function T(e){return e instanceof E}function L(e){return e instanceof H}function P(j){var E,H,P,V;if(P={highWaterMark:9007199254740992},arguments.length&&(V=function(e,t){return w(t)?k(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(c("01H2t","highWaterMark",e.highWaterMark)):null:new TypeError(c("01H2V",t))}(P,j),V))throw V;return H=function(e){var t,r;for(t=[],r=0;r0){for(t=u(x(e.byteLength)),t=y(H.length-1,t),r=H[t],s=0;sP.highWaterMark?null:(t=new v(e),E+=e,t)}(b(t)*M[r]))?s:new e(s,0,t)}function q(){var e,i,n,l,j,v,g,u,b;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:W,null===(n=d(i)))throw new TypeError(c("01H2Y",i));if(e<=0)return new n(0);if(r(arguments[0]))return Y(n,arguments[0],i);if(s(arguments[0])){if(u=(l=arguments[0]).length,o(l)?l=h(l,0):m(l)?l=a(l,0):/^complex/.test(i)&&(u/=2),null===(j=Y(n,u,i)))return j;if(L(j)||T(j))return j.set(l),j;for(g=p(l),v=f(j),b=0;b[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '01H2Y', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( /^complex/.test( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = resolveGetter( arr );\n\t\t\tset = resolveSetter( out );\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '01H2r', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( '01H2s', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'highWaterMark': 1024\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '01H2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'highWaterMark' ) ) {\n\t\topts.highWaterMark = options.highWaterMark;\n\t\tif ( !isNonNegativeInteger( opts.highWaterMark ) ) {\n\t\t\treturn new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Initializes a cache for pooled typed array buffers.\n*\n* @private\n* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size\n* @returns {ArrayArray} initialized cache\n*/\nfunction pool( n ) {\n\tvar out;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < n+1; i++ ) {\n\t\tout.push( [] );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default pool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DEFAULT_DTYPE","ARRAY_DEFAULTS","get","Complex64Array","ctors","Complex128Array","isCmplx64Array","arr","isCmplx128Array","factory","options","nbytes","pool","opts","err","highWaterMark","arguments","length","isObject","hasOwnProp","isNonNegativeInteger","TypeError","format","validate","n","out","i","push","createPool","ceil","log2","setReadOnly","malloc","nargs","tmp","reinterpret128","reinterpret64","buf","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","setReadOnlyAccessor","typedarray","ctor","len","dtype","pop","ArrayBuffer","arraybuffer","ceil2","BYTES_PER_ELEMENT","set","isString","isCollection","isComplex128Array","isComplex64Array","test","resolveGetter","resolveSetter","typedarraypool","main"],"mappings":";;q+EAoDIA,EAAgBC,EAAeC,IAAK,kBACpCC,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cAY7B,SAASE,EAAgBC,GACxB,OAASA,aAAeJ,CACzB,CASA,SAASK,EAAiBD,GACzB,OAASA,aAAeF,CACzB,CA6BA,SAASI,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,ECjFO,CACNE,cAAiB,kBDiFbC,UAAUC,SACdH,EEnEF,SAAmBD,EAAMH,GACxB,OAAMQ,EAAUR,GAGXS,EAAYT,EAAS,mBACzBG,EAAKE,cAAgBL,EAAQK,eACvBK,EAAsBP,EAAKE,gBACzB,IAAIM,UAAWC,EAAQ,QAAS,gBAAiBT,EAAKE,gBAGxD,KARC,IAAIM,UAAWC,EAAQ,QAASZ,GASzC,CFwDQa,CAAUV,EAAMH,GACjBI,GACJ,MAAMA,EAaR,OAVAF,EG5FD,SAAeY,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,CHmFQG,CAAYC,EAAMC,EAAMjB,EAAKE,iBACpCJ,EAAS,EAEToB,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,UA+JrB,WACC,IAAIC,EACAR,EACAS,EACAR,EAEJO,EAAQjB,UAAUC,OAEjBQ,EADc,IAAVQ,EACED,IACe,IAAVC,EACLD,EAAQhB,UAAW,IAEnBgB,EAAQhB,UAAW,GAAKA,UAAW,IAE1C,GAAa,OAARS,EASJ,IANCS,EADI1B,EAAiBiB,GACfU,EAAgBV,EAAK,GAChBnB,EAAgBmB,GACrBW,EAAeX,EAAK,GAEpBA,EAEDC,EAAI,EAAGA,EAAIQ,EAAIjB,OAAQS,IAC5BQ,EAAKR,GAAM,EAGb,OAAOD,CACP,IA1LDM,EAAaC,EAAQ,QAwMrB,SAAeK,GACd,IAAIb,EACAc,EACAZ,EACJ,GAAKa,EAAkBF,IAASA,EAAIG,OACnCH,EAAMA,EAAIG,YACJ,IAAMC,EAAeJ,GAC3B,MAAM,IAAIhB,UAAWC,EAAQ,QAASe,IAEvC,GAAKA,EAAIK,WAAa,EAAI,CAQzB,IAPAlB,EAAImB,EAAOb,EAAMO,EAAIK,aAGrBlB,EAAIoB,EAAKhC,EAAKK,OAAO,EAAGO,GAGxBc,EAAI1B,EAAMY,GACJE,EAAI,EAAGA,EAAIY,EAAErB,OAAQS,IAC1B,GAAKY,EAAGZ,KAAQW,EACf,OAAO,EAITC,EAAEX,KAAMU,EACR,CACD,OAAO,CACP,IAjODN,EAAaC,EAAQ,SAwOrB,WACC,IAAIN,EACJ,IAAMA,EAAI,EAAGA,EAAId,EAAKK,OAAQS,IAC7Bd,EAAMc,GAAIT,OAAS,EAEpBN,EAAS,CACT,IA7ODoB,EAAaC,EAAQ,gBAAiBnB,EAAKE,eAC3C8B,EAAqBb,EAAQ,UAU7B,WACC,OAAOrB,CACP,IAVMqB,EAmDP,SAASc,EAAYC,EAAMC,EAAKC,GAC/B,IAAIZ,EACJ,OAAa,IAARW,EACG,IAAID,EAAM,GAGL,QADbV,EArCD,SAAsBb,GACrB,IAAIa,EACAX,EAMJ,OAHAA,EAAII,EAAMN,IAGDZ,EAAKK,QAAUL,EAAMc,GAAIT,OAC1BL,EAAMc,GAAIwB,MAGbvC,EAAOa,EAAIX,EAAKE,cACb,MAERsB,EAAM,IAAIc,EAAa3B,GAGvBb,GAAUa,EAEHa,EACP,CAgBMe,CAAaC,EAAOL,GAAMM,EAAmBL,KAE3CZ,EAED,IAAIU,EAAMV,EAAK,EAAGW,EACzB,CAkBD,SAAShB,IACR,IAAIC,EACAgB,EACAF,EACAxC,EACAkB,EACA8B,EACArD,EACA8C,EACAtB,EAUJ,GALCuB,GAHDhB,EAAQjB,UAAUC,SACJuC,EAAUxC,UAAWiB,EAAM,IAEhCjB,UADRiB,GAAS,GAGDjC,EAGK,QADd+C,EAAO3C,EAAO6C,IAEb,MAAM,IAAI5B,UAAWC,EAAQ,QAAS2B,IAEvC,GAAKhB,GAAS,EACb,OAAO,IAAIc,EAAM,GAGlB,GAAK3B,EAAsBJ,UAAW,IACrC,OAAO8B,EAAYC,EAAM/B,UAAW,GAAKiC,GAG1C,GAAKQ,EAAczC,UAAW,IAAQ,CAYrC,GAVAgC,GADAzC,EAAMS,UAAW,IACPC,OACLyC,EAAmBnD,GACvBA,EAAM4B,EAAgB5B,EAAK,GAChBoD,EAAkBpD,GAC7BA,EAAM6B,EAAe7B,EAAK,GACf,WAAWqD,KAAMX,KAE5BD,GAAO,GAGK,QADbvB,EAAMqB,EAAYC,EAAMC,EAAKC,IAE5B,OAAOxB,EAER,GAAKjB,EAAiBiB,IAASnB,EAAgBmB,GAE9C,OADAA,EAAI8B,IAAKhD,GACFkB,EAKR,IAFAvB,EAAM2D,EAAetD,GACrBgD,EAAMO,EAAerC,GACfC,EAAI,EAAGA,EAAIsB,EAAKtB,IACrB6B,EAAK9B,EAAKC,EAAGxB,EAAKK,EAAKmB,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,QAASN,UAAW,IACjD,CAkGF,CIrTG,IAAC+C,EAAiBtD,ICPrBsB,EAAAiC,EAAA,UAAAvD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2b69d1f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From df3c6478a0c49dab8e93f6520b1528bc417b4252 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jul 2024 19:25:01 +0000 Subject: [PATCH 091/103] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 133 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.calloc.js | 265 -- benchmark/benchmark.factory.js | 71 - benchmark/benchmark.js | 265 -- benchmark/benchmark.length.bool.js | 102 - benchmark/benchmark.length.complex128.js | 102 - benchmark/benchmark.length.complex64.js | 102 - benchmark/benchmark.length.float32.js | 102 - benchmark/benchmark.length.float64.js | 102 - benchmark/benchmark.length.int16.js | 102 - benchmark/benchmark.length.int32.js | 102 - benchmark/benchmark.length.int8.js | 102 - benchmark/benchmark.length.uint16.js | 102 - benchmark/benchmark.length.uint32.js | 102 - benchmark/benchmark.length.uint8.js | 102 - benchmark/benchmark.length.uint8c.js | 102 - benchmark/benchmark.malloc.js | 265 -- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 53 - dist/index.js.map | 7 - docs/repl.txt | 333 -- docs/types/test.ts | 193 - examples/index.js | 80 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/bytes_per_element.json | 14 - lib/defaults.js | 42 - lib/factory.js | 391 -- lib/index.js | 56 - lib/main.js | 63 - lib/pool.js | 44 - lib/validate.js | 66 - package.json | 104 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 2401 ---------- test/test.js | 1935 -------- 63 files changed, 4872 insertions(+), 11299 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.calloc.js delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.bool.js delete mode 100644 benchmark/benchmark.length.complex128.js delete mode 100644 benchmark/benchmark.length.complex64.js delete mode 100644 benchmark/benchmark.length.float32.js delete mode 100644 benchmark/benchmark.length.float64.js delete mode 100644 benchmark/benchmark.length.int16.js delete mode 100644 benchmark/benchmark.length.int32.js delete mode 100644 benchmark/benchmark.length.int8.js delete mode 100644 benchmark/benchmark.length.uint16.js delete mode 100644 benchmark/benchmark.length.uint32.js delete mode 100644 benchmark/benchmark.length.uint8.js delete mode 100644 benchmark/benchmark.length.uint8c.js delete mode 100644 benchmark/benchmark.malloc.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/bytes_per_element.json delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/pool.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ea35f20..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/array/pool) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6f7c875..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/array/pool) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 869c4e9..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f92a6c5..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -481,7 +478,7 @@ console.log( 'nbytes: %d', typedarray.nbytes ); ## 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]. @@ -548,11 +545,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-arraybuffer]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer -[@stdlib/array/typed-dtypes]: https://github.com/stdlib-js/array-typed-dtypes +[@stdlib/array/typed-dtypes]: https://github.com/stdlib-js/array-typed-dtypes/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/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.calloc.js b/benchmark/benchmark.calloc.js deleted file mode 100644 index 2a04c65..0000000 --- a/benchmark/benchmark.calloc.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var isBooleanArray = require( '@stdlib/assert-is-booleanarray' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':calloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=bool', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'bool' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isBooleanArray( arr ) ) { - b.fail( 'should return a boolean array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 58918bb..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = typedarray.factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:highWaterMark', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'highWaterMark': 0 - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.highWaterMark = i; - f = typedarray.factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9512bbb..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var isBooleanArray = require('@stdlib/assert-is-booleanarray'); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=bool', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'bool' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isBooleanArray( arr ) ) { - b.fail( 'should return a boolean array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.bool.js b/benchmark/benchmark.length.bool.js deleted file mode 100644 index d9ad47b..0000000 --- a/benchmark/benchmark.length.bool.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isBooleanArray = require( '@stdlib/assert-is-booleanarray' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'bool' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isBooleanArray( arr ) ) { - b.fail( 'should return a boolean array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=bool,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=bool,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=bool,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex128.js b/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 12c6668..0000000 --- a/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex64.js b/benchmark/benchmark.length.complex64.js deleted file mode 100644 index ca2b45c..0000000 --- a/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float32.js b/benchmark/benchmark.length.float32.js deleted file mode 100644 index b3b4508..0000000 --- a/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float64.js b/benchmark/benchmark.length.float64.js deleted file mode 100644 index 5f0132d..0000000 --- a/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int16.js b/benchmark/benchmark.length.int16.js deleted file mode 100644 index 9f253cb..0000000 --- a/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int32.js b/benchmark/benchmark.length.int32.js deleted file mode 100644 index f83e795..0000000 --- a/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int8.js b/benchmark/benchmark.length.int8.js deleted file mode 100644 index 5b01174..0000000 --- a/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint16.js b/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 32b0a5d..0000000 --- a/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint32.js b/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 290b90c..0000000 --- a/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8.js b/benchmark/benchmark.length.uint8.js deleted file mode 100644 index ff7d733..0000000 --- a/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8c.js b/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index 8f0d10a..0000000 --- a/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.malloc.js b/benchmark/benchmark.malloc.js deleted file mode 100644 index c85d2fb..0000000 --- a/benchmark/benchmark.malloc.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var isBooleanArray = require( '@stdlib/assert-is-booleanarray' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':malloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=bool', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'bool' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isBooleanArray( arr ) ) { - b.fail( 'should return a boolean array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 612de17..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/array/pool" -%% click B href "https://github.com/stdlib-js/array-pool/tree/main" -%% click C href "https://github.com/stdlib-js/array-pool/tree/production" -%% click D href "https://github.com/stdlib-js/array-pool/tree/esm" -%% click E href "https://github.com/stdlib-js/array-pool/tree/deno" -%% click F href "https://github.com/stdlib-js/array-pool/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/pool -[production-url]: https://github.com/stdlib-js/array-pool/tree/production -[deno-url]: https://github.com/stdlib-js/array-pool/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-pool/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-pool/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-pool/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-pool/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-pool/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 5160b6f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import typedarraypool from '../docs/types/index'; -export = typedarraypool; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 925147b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,53 +0,0 @@ -"use strict";var s=function(n,i){return function(){return i||n((i={exports:{}}).exports,i),i.exports}};var M=s(function(Cr,w){"use strict";function z(){return{highWaterMark:9007199254740992}}w.exports=z});var T=s(function(Or,E){"use strict";var G=require("@stdlib/assert-is-plain-object"),H=require("@stdlib/assert-has-own-property"),J=require("@stdlib/assert-is-nonnegative-integer").isPrimitive,k=require("@stdlib/string-format");function K(n,i){return G(i)?H(i,"highWaterMark")&&(n.highWaterMark=i.highWaterMark,!J(n.highWaterMark))?new TypeError(k("invalid option. `%s` option must be a nonnegative integer. Option: `%s`.","highWaterMark",n.highWaterMark)):null:new TypeError(k("invalid argument. Options argument must be an object. Value: `%s`.",i))}E.exports=K});var B=s(function(Pr,W){"use strict";function Q(n){var i,u;for(i=[],u=0;uv.highWaterMark?null:(e=new fr(r),i+=r,e)}function d(r,e,t){var a;return e===0?new r(0):(a=F(pr(e)*dr[t]),a===null?a:new r(a,0,e))}function o(){var r,e,t,a,l,A,x,c,f;if(r=arguments.length,r&&Z(arguments[r-1])?(r-=1,e=arguments[r]):e=Ar,t=p(e),t===null)throw new TypeError(y("invalid argument. Must provide a recognized data type. Value: `%s`.",e));if(r<=0)return new t(0);if($(arguments[0]))return d(t,arguments[0],e);if(rr(arguments[0])){if(a=arguments[0],c=a.length,nr(a)?a=O(a,0):ir(a)?a=C(a,0):ur(a)?a=P(a,0):tr(e)&&(c/=2),l=d(t,c,e),l===null)return l;if(R(l)||L(l)||N(l))return l.set(a),l;for(x=lr(a),A=sr(l),f=0;f0){for(e=cr(m(r.byteLength)),e=hr(u.length-1,e),t=u[e],a=0;a[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( isBooleanArray( arr ) ) {\n\t\t\t\tarr = reinterpretBoolean( arr, 0 );\n\t\t\t} else if ( isComplexDataType( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) || isBoolArray( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = resolveGetter( arr );\n\t\t\tset = resolveSetter( out );\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else if ( isBoolArray( out ) ) {\n\t\t\t\ttmp = reinterpretBoolean( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nmodule.exports = typedarraypool;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* var typedarraypool = require( '@stdlib/array-pool' );\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,cAAiB,gBAClB,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,eAAgB,IACzCD,EAAK,cAAgBC,EAAQ,cACxB,CAACJ,EAAsBG,EAAK,aAAc,GACvC,IAAI,UAAWF,EAAQ,2EAA4E,gBAAiBE,EAAK,aAAc,CAAE,EAG3I,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cA6BA,SAASC,EAAM,EAAI,CAClB,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAI,EAAE,EAAGA,IACrBD,EAAI,KAAM,CAAC,CAAE,EAEd,OAAOA,CACR,CAKAF,EAAO,QAAUC,IC3CjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,KAAQ,EACR,QAAW,EACX,QAAW,EACX,MAAS,EACT,MAAS,EACT,KAAQ,EACR,OAAU,EACV,OAAU,EACV,MAAS,EACT,OAAU,EACT,UAAa,EACb,WAAc,EAChB,ICbA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,GAAe,QAAS,8BAA+B,EACvDC,GAAmB,QAAS,oCAAqC,EACjEC,GAAgB,QAAS,+BAAgC,EACzDC,GAAoB,QAAS,+DAAgE,EAC7FC,GAAmB,QAAS,kCAAmC,EAC/DC,GAAoB,QAAS,mCAAoC,EACjEC,GAAiB,QAAS,gCAAiC,EAC3DC,EAAc,QAAS,uDAAwD,EAC/EC,GAAsB,QAAS,uDAAwD,EACvFC,EAAQ,QAAS,2BAA4B,EAC7CC,EAAgB,QAAS,4CAA6C,EACtEC,EAAiB,QAAS,6CAA8C,EACxEC,EAAqB,QAAS,0CAA2C,EACzEC,GAAgB,QAAS,mCAAoC,EAC7DC,GAAgB,QAAS,mCAAoC,EAC7DC,GAAiB,QAAS,wBAAyB,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,GAAc,QAAS,sBAAuB,EAC9CC,GAAO,QAAS,gCAAiC,EACjDC,GAAQ,QAAS,iCAAkC,EACnDC,GAAQ,QAAS,iCAAkC,EACnDC,EAAO,QAAS,gCAAiC,EACjDC,GAAM,QAAS,+BAAgC,EAC/CC,GAAW,IACXC,GAAW,IACXC,GAAa,IACbC,GAAoB,IAKpBC,GAAgBZ,GAAe,IAAK,gBAAiB,EACrDa,GAAiBnB,EAAO,WAAY,EACpCoB,GAAkBpB,EAAO,YAAa,EACtCqB,GAAerB,EAAO,MAAO,EAYjC,SAASsB,EAAgBC,EAAM,CAC9B,OAASA,aAAeJ,EACzB,CASA,SAASK,EAAiBD,EAAM,CAC/B,OAASA,aAAeH,EACzB,CASA,SAASK,EAAaF,EAAM,CAC3B,OAASA,aAAeF,EACzB,CA6BA,SAASK,GAASC,EAAU,CAC3B,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,EAAOhB,GAAS,EACX,UAAU,SACdiB,EAAMhB,GAAUe,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAAF,EAAOb,GAAYP,GAAMG,EAAMkB,EAAK,aAAc,CAAE,CAAE,EACtDF,EAAS,EAET9B,EAAakC,EAAQ,SAAUA,CAAO,EACtClC,EAAakC,EAAQ,SAAUC,CAAO,EACtCnC,EAAakC,EAAQ,OAAQE,CAAK,EAClCpC,EAAakC,EAAQ,QAASG,CAAM,EACpCrC,EAAakC,EAAQ,gBAAiBF,EAAK,aAAc,EACzD/B,GAAqBiC,EAAQ,SAAUI,CAAS,EAEzCJ,EAQP,SAASI,GAAW,CACnB,OAAOR,CACR,CASA,SAASS,EAAaC,EAAI,CACzB,IAAIC,EACAC,EAMJ,OAHAA,EAAI5B,EAAM0B,CAAE,EAGPE,EAAIX,EAAK,QAAUA,EAAMW,CAAE,EAAE,OAC1BX,EAAMW,CAAE,EAAE,IAAI,EAGjBZ,EAAOU,EAAIR,EAAK,cACb,MAERS,EAAM,IAAI/B,GAAa8B,CAAE,EAGzBV,GAAUU,EAEHC,EACR,CAWA,SAASE,EAAYC,EAAMC,EAAKC,EAAQ,CACvC,IAAIL,EACJ,OAAKI,IAAQ,EACL,IAAID,EAAM,CAAE,GAEpBH,EAAMF,EAAa1B,GAAOgC,CAAI,EAAE1B,GAAmB2B,CAAM,CAAE,EACtDL,IAAQ,KACLA,EAED,IAAIG,EAAMH,EAAK,EAAGI,CAAI,EAC9B,CAkBA,SAASX,GAAS,CACjB,IAAIa,EACAD,EACAF,EACAnB,EACAuB,EACAC,EACAC,EACAL,EACAH,EAUJ,GARAK,EAAQ,UAAU,OACbA,GAASxD,EAAU,UAAWwD,EAAM,CAAE,CAAE,GAC5CA,GAAS,EACTD,EAAQ,UAAWC,CAAM,GAEzBD,EAAQ1B,GAETwB,EAAO1C,EAAO4C,CAAM,EACfF,IAAS,KACb,MAAM,IAAI,UAAWnC,EAAQ,sEAAuEqC,CAAM,CAAE,EAE7G,GAAKC,GAAS,EACb,OAAO,IAAIH,EAAM,CAAE,EAGpB,GAAKpD,EAAsB,UAAW,CAAE,CAAE,EACzC,OAAOmD,EAAYC,EAAM,UAAW,CAAE,EAAGE,CAAM,EAGhD,GAAKrD,GAAc,UAAW,CAAE,CAAE,EAAI,CAcrC,GAbAgC,EAAM,UAAW,CAAE,EACnBoB,EAAMpB,EAAI,OACL3B,GAAmB2B,CAAI,EAC3BA,EAAMrB,EAAgBqB,EAAK,CAAE,EAClB5B,GAAkB4B,CAAI,EACjCA,EAAMtB,EAAesB,EAAK,CAAE,EACjB1B,GAAgB0B,CAAI,EAC/BA,EAAMpB,EAAoBoB,EAAK,CAAE,EACtB7B,GAAmBkD,CAAM,IAEpCD,GAAO,GAERG,EAAML,EAAYC,EAAMC,EAAKC,CAAM,EAC9BE,IAAQ,KACZ,OAAOA,EAER,GAAKtB,EAAiBsB,CAAI,GAAKxB,EAAgBwB,CAAI,GAAKrB,EAAaqB,CAAI,EACxE,OAAAA,EAAI,IAAKvB,CAAI,EACNuB,EAKR,IAFAE,EAAM5C,GAAemB,CAAI,EACzBwB,EAAM1C,GAAeyC,CAAI,EACnBN,EAAI,EAAGA,EAAIG,EAAKH,IACrBO,EAAKD,EAAKN,EAAGQ,EAAKzB,EAAKiB,CAAE,CAAE,EAE5B,OAAOM,CACR,CACA,MAAM,IAAI,UAAWvC,EAAQ,wGAAyG,UAAW,CAAE,CAAE,CAAE,CACxJ,CAgBA,SAAS0B,GAAS,CACjB,IAAIY,EACAC,EACAG,EACAT,EAUJ,GARAK,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAMd,EAAO,EACFa,IAAU,EACrBC,EAAMd,EAAQ,UAAW,CAAE,CAAE,EAE7Bc,EAAMd,EAAQ,UAAW,CAAE,EAAG,UAAW,CAAE,CAAE,EAEzCc,IAAQ,KAWZ,IATKtB,EAAiBsB,CAAI,EACzBG,EAAM/C,EAAgB4C,EAAK,CAAE,EAClBxB,EAAgBwB,CAAI,EAC/BG,EAAMhD,EAAe6C,EAAK,CAAE,EACjBrB,EAAaqB,CAAI,EAC5BG,EAAM9C,EAAoB2C,EAAK,CAAE,EAEjCG,EAAMH,EAEDN,EAAI,EAAGA,EAAIS,EAAI,OAAQT,IAC5BS,EAAKT,CAAE,EAAI,EAGb,OAAOM,CACR,CAcA,SAASZ,EAAMK,EAAM,CACpB,IAAID,EACAY,EACAV,EACJ,GAAKhD,GAAkB+C,CAAI,GAAKA,EAAI,OACnCA,EAAMA,EAAI,eACC,CAAC9C,GAAe8C,CAAI,EAC/B,MAAM,IAAI,UAAWhC,EAAQ,4EAA6EgC,CAAI,CAAE,EAEjH,GAAKA,EAAI,WAAa,EAAI,CAQzB,IAPAD,EAAI5B,GAAOE,EAAM2B,EAAI,UAAW,CAAE,EAGlCD,EAAIzB,GAAKgB,EAAK,OAAO,EAAGS,CAAE,EAG1BY,EAAIrB,EAAMS,CAAE,EACNE,EAAI,EAAGA,EAAIU,EAAE,OAAQV,IAC1B,GAAKU,EAAGV,CAAE,IAAMD,EACf,MAAO,GAITW,EAAE,KAAMX,CAAI,CACb,CACA,MAAO,EACR,CAOA,SAASJ,GAAQ,CAChB,IAAIK,EACJ,IAAMA,EAAI,EAAGA,EAAIX,EAAK,OAAQW,IAC7BX,EAAMW,CAAE,EAAE,OAAS,EAEpBZ,EAAS,CACV,CACD,CAKAxC,EAAO,QAAUsC,KCtYjB,IAAAyB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAU,IAmCVC,GAAiBD,GAAQ,EAK7BD,EAAO,QAAUE,KCnBjB,IAAIC,GAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,GAAU,IAKdF,GAAaC,EAAM,UAAWC,EAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isNonNegativeInteger", "format", "validate", "opts", "options", "require_pool", "__commonJSMin", "exports", "module", "pool", "out", "i", "require_bytes_per_element", "__commonJSMin", "exports", "module", "require_factory", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isCollection", "isTypedArrayLike", "isArrayBuffer", "isComplexDataType", "isComplex64Array", "isComplex128Array", "isBooleanArray", "setReadOnly", "setReadOnlyAccessor", "ctors", "reinterpret64", "reinterpret128", "reinterpretBoolean", "resolveGetter", "resolveSetter", "ARRAY_DEFAULTS", "format", "ArrayBuffer", "ceil", "floor", "ceil2", "log2", "min", "defaults", "validate", "createPool", "BYTES_PER_ELEMENT", "DEFAULT_DTYPE", "Complex64Array", "Complex128Array", "BooleanArray", "isCmplx64Array", "arr", "isCmplx128Array", "isBoolArray", "factory", "options", "nbytes", "pool", "opts", "err", "malloc", "calloc", "free", "clear", "getBytes", "arraybuffer", "n", "buf", "i", "typedarray", "ctor", "len", "dtype", "nargs", "out", "set", "get", "tmp", "p", "require_main", "__commonJSMin", "exports", "module", "factory", "typedarraypool", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a2727d6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,333 +0,0 @@ - -{{alias}}( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - Memory is **uninitialized**, which means that the contents of a returned - typed array may contain sensitive contents. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}() - [] - > arr = {{alias}}( 'float32' ) - [] - - -{{alias}}( length[, dtype] ) - Returns an uninitialized typed array having a specified length from a typed - array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > arr = {{alias}}( 5, 'int32' ) - - - -{{alias}}( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - This method shares the same security vulnerabilities mentioned above. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc() - - > arr = {{alias}}.malloc( 'float32' ) - - - -{{alias}}.malloc( length[, dtype] ) - Returns a typed array having a specified length from a typed array memory - pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc( 5 ) - - > arr = {{alias}}.malloc( 5, 'int32' ) - - - -{{alias}}.malloc( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}.malloc( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.calloc( [dtype] ) - Returns a zero-initialized typed array from a typed array memory pool. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc() - [] - > arr = {{alias}}.calloc( 'float32' ) - [] - - -{{alias}}.calloc( length[, dtype] ) - Returns a zero-initialized typed array having a specified length from a - typed array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}.calloc( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}.free( buf ) - Frees a typed array or typed array buffer for use in a future allocation. - - Parameters - ---------- - buf: TypedArray|ArrayBuffer - Typed array or typed array buffer to free. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - - -{{alias}}.clear() - Clears the typed array pool allowing garbage collection of previously - allocated (and currently free) array buffers. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - > {{alias}}.clear(); - - -{{alias}}.highWaterMark - Read-only property returning the pool's high water mark. - - Once a high water mark is reached, typed array allocation fails. - - Examples - -------- - > {{alias}}.highWaterMark - - - -{{alias}}.nbytes - Read-only property returning the total number of allocated bytes. - - The returned value is the total accumulated value. Hence, anytime a pool - must allocate a new array buffer (i.e., more memory), the pool increments - this value. - - The only time this value is decremented is when a pool is cleared. - - This behavior means that, while allocated buffers which are never freed may, - in fact, be garbage collected, they continue to count against the high water - mark limit. - - Accordingly, you should *always* free allocated buffers in order to prevent - the pool from believing that non-freed buffers are continually in use. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.nbytes - - - -{{alias}}.factory( [options] ) - Creates a typed array pool. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.highWaterMark: integer (optional) - Maximum total memory (in bytes) which can be allocated. - - Returns - ------- - fcn: Function - Function for creating typed arrays from a typed array memory pool. - - Examples - -------- - > var pool = {{alias}}.factory(); - > var arr1 = pool( 3, 'float64' ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 4336c42..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,193 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-empty */ -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import typedarraypool = require( './index' ); - - -// TESTS // - -// The function returns a typed array or null... -{ - typedarraypool(); // $ExpectType TypedArrayOrNull - typedarraypool( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the function is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool( true ); // $ExpectError - typedarraypool( false ); // $ExpectError - typedarraypool( null ); // $ExpectError - typedarraypool( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized data type... -{ - typedarraypool( 4, true ); // $ExpectError - typedarraypool( 4, false ); // $ExpectError - typedarraypool( 4, null ); // $ExpectError - typedarraypool( 4, 'abc' ); // $ExpectError - typedarraypool( 4, 123 ); // $ExpectError - typedarraypool( 4, [] ); // $ExpectError - typedarraypool( 4, {} ); // $ExpectError - typedarraypool( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an incorrect number of arguments... -{ - typedarraypool( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `malloc` method which returns a typed array or null... -{ - typedarraypool.malloc(); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.malloc( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `malloc` method is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool.malloc( true ); // $ExpectError - typedarraypool.malloc( false ); // $ExpectError - typedarraypool.malloc( null ); // $ExpectError - typedarraypool.malloc( {} ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.malloc( 4, true ); // $ExpectError - typedarraypool.malloc( 4, false ); // $ExpectError - typedarraypool.malloc( 4, null ); // $ExpectError - typedarraypool.malloc( 4, 'abc' ); // $ExpectError - typedarraypool.malloc( 4, 123 ); // $ExpectError - typedarraypool.malloc( 4, [] ); // $ExpectError - typedarraypool.malloc( 4, {} ); // $ExpectError - typedarraypool.malloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided an incorrect number of arguments... -{ - typedarraypool.malloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `calloc` method which returns a typed array or null... -{ - typedarraypool.calloc(); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `calloc` method is provided a first argument which is not a number... -{ - typedarraypool.calloc( 'abc' ); // $ExpectError - typedarraypool.calloc( true ); // $ExpectError - typedarraypool.calloc( false ); // $ExpectError - typedarraypool.calloc( null ); // $ExpectError - typedarraypool.calloc( {} ); // $ExpectError - typedarraypool.calloc( [] ); // $ExpectError - typedarraypool.calloc( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.calloc( 4, true ); // $ExpectError - typedarraypool.calloc( 4, false ); // $ExpectError - typedarraypool.calloc( 4, null ); // $ExpectError - typedarraypool.calloc( 4, 'abc' ); // $ExpectError - typedarraypool.calloc( 4, 123 ); // $ExpectError - typedarraypool.calloc( 4, [] ); // $ExpectError - typedarraypool.calloc( 4, {} ); // $ExpectError - typedarraypool.calloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided an incorrect number of arguments... -{ - typedarraypool.calloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `factory` method which returns a typed array pool.. -{ - typedarraypool.factory(); // $ExpectType Pool - typedarraypool.factory( { 'highWaterMark': 556 } ); // $ExpectType Pool -} - -// The compiler throws an error if the `factory` method is provided a `highWaterMark` option which is not a number... -{ - typedarraypool.factory( { 'highWaterMark': true } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': false } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': 'abc' } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': null } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': [] } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': {} } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an incorrect number of arguments... -{ - typedarraypool.factory( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` method which returns void... -{ - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.free( arr ); // $ExpectType void -} - -// The compiler throws an error if the `free` method is provided a first argument which is neither a typed array nor array buffer... -{ - typedarraypool.free( true ); // $ExpectError - typedarraypool.free( false ); // $ExpectError - typedarraypool.free( 123 ); // $ExpectError - typedarraypool.free( 'abc' ); // $ExpectError - typedarraypool.free( null ); // $ExpectError - typedarraypool.free( {} ); // $ExpectError - typedarraypool.free( ( x: number ): number => x ); // $ExpectError -} - -// Attached to the main export is a `clear` method which returns void... -{ - typedarraypool.clear(); // $ExpectType void -} - -// The compiler throws an error if the `clear` method is provided arguments... -{ - typedarraypool.clear( {} ); // $ExpectError - typedarraypool.clear( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `highWaterMark` property... -{ - typedarraypool.highWaterMark; // $ExpectType number -} - -// Attached to the main export is a `nbytes` property... -{ - typedarraypool.nbytes; // $ExpectType number -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 24a7846..0000000 --- a/examples/index.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 randu = require( '@stdlib/random-base-randu' ); -var typedarraypool = require( './../lib' ); - -// Create a typed array pool which can allocate at most 1GB: -var typedarray = typedarraypool.factory({ - 'highWaterMark': 1e9 -}); - -// Inspect the pool: -console.log( 'Max bytes: %d', typedarray.highWaterMark ); -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Allocate an array for storing double-precision floating-point numbers: -var arr1 = typedarray( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Fill the array... -var i; -for ( i = 0; i < arr1.length; i++ ) { - arr1[ i ] = randu(); -} - -// Inspect array contents: -console.log( arr1 ); - -// Free the array: -typedarray.free( arr1 ); - -// Allocate another array similar to the previous one: -var arr2 = typedarray( 5, 'float64' ); -// returns - -// Check that we have been returned a new typed array view: -console.log( arr2 === arr1 ); -// => false - -// Inspect array contents: -console.log( arr2 ); - -// Free the array: -typedarray.free( arr2 ); - -// Allocate an initialized array: -var arr3 = typedarray.calloc( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect array contents: -console.log( arr3 ); - -// Free the array: -typedarray.free( arr3 ); - -// Clear the pool: -typedarray.clear(); - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 4dc8736..8298bf3 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike, RealOrComplexTypedArray, BooleanArray, NumericDataType as DataType } from '@stdlib/types/array'; import ArrayBuffer = require( '@stdlib/array-buffer' ); diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..1857d00 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-booleanarray@v0.0.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.2.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.2.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.1-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-setter@v0.2.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/array-defaults@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.1-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.2.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.2.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.2.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.2.1-esm/index.mjs";import M from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.2.2-esm/index.mjs";import W from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";var H={bool:1,float64:8,float32:4,int16:2,int32:4,int8:1,uint16:2,uint32:4,uint8:1,uint8c:1,complex64:8,complex128:16},T=g.get("dtypes.default"),L=h("complex64"),P=h("complex128"),V=h("bool");function Y(e){return e instanceof L}function q(e){return e instanceof P}function z(e){return e instanceof V}function A(g){var L,P,V,A;if(V={highWaterMark:9007199254740992},arguments.length&&(A=function(e,t){return W(t)?E(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(u("01H2t","highWaterMark",e.highWaterMark)):null:new TypeError(u("01H2V",t))}(V,g),A))throw A;return P=function(e){var t,r;for(t=[],r=0;r0){for(t=y(k(e.byteLength)),t=M(P.length-1,t),r=P[t],s=0;sV.highWaterMark?null:(t=new b(e),L+=e,t)}(w(t)*H[r]))?s:new e(s,0,t)}function C(){var e,i,n,a,g,b,x,y,w;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:T,null===(n=h(i)))throw new TypeError(u("01H2Y",i));if(e<=0)return new n(0);if(r(arguments[0]))return B(n,arguments[0],i);if(s(arguments[0])){if(y=(a=arguments[0]).length,d(a)?a=j(a,0):m(a)?a=p(a,0):l(a)?a=f(a,0):o(i)&&(y/=2),null===(g=B(n,y,i)))return g;if(q(g)||Y(g)||z(g))return g.set(a),g;for(x=c(a),b=v(g),w=0;w[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '01H2Y', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( isBooleanArray( arr ) ) {\n\t\t\t\tarr = reinterpretBoolean( arr, 0 );\n\t\t\t} else if ( isComplexDataType( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) || isBoolArray( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = resolveGetter( arr );\n\t\t\tset = resolveSetter( out );\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '01H2r', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else if ( isBoolArray( out ) ) {\n\t\t\t\ttmp = reinterpretBoolean( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( '01H2s', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'highWaterMark': 1024\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '01H2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'highWaterMark' ) ) {\n\t\topts.highWaterMark = options.highWaterMark;\n\t\tif ( !isNonNegativeInteger( opts.highWaterMark ) ) {\n\t\t\treturn new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Initializes a cache for pooled typed array buffers.\n*\n* @private\n* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size\n* @returns {ArrayArray} initialized cache\n*/\nfunction pool( n ) {\n\tvar out;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < n+1; i++ ) {\n\t\tout.push( [] );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default pool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DEFAULT_DTYPE","ARRAY_DEFAULTS","get","Complex64Array","ctors","Complex128Array","BooleanArray","isCmplx64Array","arr","isCmplx128Array","isBoolArray","factory","options","nbytes","pool","opts","err","highWaterMark","arguments","length","isObject","hasOwnProp","isNonNegativeInteger","TypeError","format","validate","n","out","i","push","createPool","ceil","log2","setReadOnly","malloc","nargs","tmp","reinterpret128","reinterpret64","reinterpretBoolean","buf","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","setReadOnlyAccessor","typedarray","ctor","len","dtype","pop","ArrayBuffer","arraybuffer","ceil2","BYTES_PER_ELEMENT","set","isString","isCollection","isComplex128Array","isComplex64Array","isBooleanArray","isComplexDataType","resolveGetter","resolveSetter","typedarraypool","main"],"mappings":";;wzFAuDIA,EAAgBC,EAAeC,IAAK,kBACpCC,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cACzBE,EAAeF,EAAO,QAY1B,SAASG,EAAgBC,GACxB,OAASA,aAAeL,CACzB,CASA,SAASM,EAAiBD,GACzB,OAASA,aAAeH,CACzB,CASA,SAASK,EAAaF,GACrB,OAASA,aAAeF,CACzB,CA6BA,SAASK,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,EChGO,CACNE,cAAiB,kBDgGbC,UAAUC,SACdH,EElFF,SAAmBD,EAAMH,GACxB,OAAMQ,EAAUR,GAGXS,EAAYT,EAAS,mBACzBG,EAAKE,cAAgBL,EAAQK,eACvBK,EAAsBP,EAAKE,gBACzB,IAAIM,UAAWC,EAAQ,QAAS,gBAAiBT,EAAKE,gBAGxD,KARC,IAAIM,UAAWC,EAAQ,QAASZ,GASzC,CFuEQa,CAAUV,EAAMH,GACjBI,GACJ,MAAMA,EAaR,OAVAF,EG3GD,SAAeY,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,CHkGQG,CAAYC,EAAMC,EAAMjB,EAAKE,iBACpCJ,EAAS,EAEToB,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,UAiKrB,WACC,IAAIC,EACAR,EACAS,EACAR,EAEJO,EAAQjB,UAAUC,OAEjBQ,EADc,IAAVQ,EACED,IACe,IAAVC,EACLD,EAAQhB,UAAW,IAEnBgB,EAAQhB,UAAW,GAAKA,UAAW,IAE1C,GAAa,OAARS,EAWJ,IARCS,EADI3B,EAAiBkB,GACfU,EAAgBV,EAAK,GAChBpB,EAAgBoB,GACrBW,EAAeX,EAAK,GACfjB,EAAaiB,GAClBY,EAAoBZ,EAAK,GAEzBA,EAEDC,EAAI,EAAGA,EAAIQ,EAAIjB,OAAQS,IAC5BQ,EAAKR,GAAM,EAGb,OAAOD,CACP,IA9LDM,EAAaC,EAAQ,QA4MrB,SAAeM,GACd,IAAId,EACAe,EACAb,EACJ,GAAKc,EAAkBF,IAASA,EAAIG,OACnCH,EAAMA,EAAIG,YACJ,IAAMC,EAAeJ,GAC3B,MAAM,IAAIjB,UAAWC,EAAQ,QAASgB,IAEvC,GAAKA,EAAIK,WAAa,EAAI,CAQzB,IAPAnB,EAAIoB,EAAOd,EAAMQ,EAAIK,aAGrBnB,EAAIqB,EAAKjC,EAAKK,OAAO,EAAGO,GAGxBe,EAAI3B,EAAMY,GACJE,EAAI,EAAGA,EAAIa,EAAEtB,OAAQS,IAC1B,GAAKa,EAAGb,KAAQY,EACf,OAAO,EAITC,EAAEZ,KAAMW,EACR,CACD,OAAO,CACP,IArODP,EAAaC,EAAQ,SA4OrB,WACC,IAAIN,EACJ,IAAMA,EAAI,EAAGA,EAAId,EAAKK,OAAQS,IAC7Bd,EAAMc,GAAIT,OAAS,EAEpBN,EAAS,CACT,IAjPDoB,EAAaC,EAAQ,gBAAiBnB,EAAKE,eAC3C+B,EAAqBd,EAAQ,UAU7B,WACC,OAAOrB,CACP,IAVMqB,EAmDP,SAASe,EAAYC,EAAMC,EAAKC,GAC/B,IAAIZ,EACJ,OAAa,IAARW,EACG,IAAID,EAAM,GAGL,QADbV,EArCD,SAAsBd,GACrB,IAAIc,EACAZ,EAMJ,OAHAA,EAAII,EAAMN,IAGDZ,EAAKK,QAAUL,EAAMc,GAAIT,OAC1BL,EAAMc,GAAIyB,MAGbxC,EAAOa,EAAIX,EAAKE,cACb,MAERuB,EAAM,IAAIc,EAAa5B,GAGvBb,GAAUa,EAEHc,EACP,CAgBMe,CAAaC,EAAOL,GAAMM,EAAmBL,KAE3CZ,EAED,IAAIU,EAAMV,EAAK,EAAGW,EACzB,CAkBD,SAASjB,IACR,IAAIC,EACAiB,EACAF,EACA1C,EACAmB,EACA+B,EACAxD,EACAiD,EACAvB,EAUJ,GALCwB,GAHDjB,EAAQjB,UAAUC,SACJwC,EAAUzC,UAAWiB,EAAM,IAEhCjB,UADRiB,GAAS,GAGDnC,EAGK,QADdkD,EAAO9C,EAAOgD,IAEb,MAAM,IAAI7B,UAAWC,EAAQ,QAAS4B,IAEvC,GAAKjB,GAAS,EACb,OAAO,IAAIe,EAAM,GAGlB,GAAK5B,EAAsBJ,UAAW,IACrC,OAAO+B,EAAYC,EAAMhC,UAAW,GAAKkC,GAG1C,GAAKQ,EAAc1C,UAAW,IAAQ,CAcrC,GAZAiC,GADA3C,EAAMU,UAAW,IACPC,OACL0C,EAAmBrD,GACvBA,EAAM6B,EAAgB7B,EAAK,GAChBsD,EAAkBtD,GAC7BA,EAAM8B,EAAe9B,EAAK,GACfuD,EAAgBvD,GAC3BA,EAAM+B,EAAoB/B,EAAK,GACpBwD,EAAmBZ,KAE9BD,GAAO,GAGK,QADbxB,EAAMsB,EAAYC,EAAMC,EAAKC,IAE5B,OAAOzB,EAER,GAAKlB,EAAiBkB,IAASpB,EAAgBoB,IAASjB,EAAaiB,GAEpE,OADAA,EAAI+B,IAAKlD,GACFmB,EAKR,IAFAzB,EAAM+D,EAAezD,GACrBkD,EAAMQ,EAAevC,GACfC,EAAI,EAAGA,EAAIuB,EAAKvB,IACrB8B,EAAK/B,EAAKC,EAAG1B,EAAKM,EAAKoB,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,QAASN,UAAW,IACjD,CAoGF,CIxUG,IAACiD,EAAiBxD,ICPrBsB,EAAAmC,EAAA,UAAAzD"} \ No newline at end of file diff --git a/lib/bytes_per_element.json b/lib/bytes_per_element.json deleted file mode 100644 index 30f02fc..0000000 --- a/lib/bytes_per_element.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "bool": 1, - "float64": 8, - "float32": 4, - "int16": 2, - "int32": 4, - "int8": 1, - "uint16": 2, - "uint32": 4, - "uint8": 1, - "uint8c": 1, - "complex64": 8, - "complex128": 16 -} diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index a421711..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +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'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'highWaterMark': 9007199254740992 - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 7f297ce..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,391 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' ); -var isComplex64Array = require( '@stdlib/assert-is-complex64array' ); -var isComplex128Array = require( '@stdlib/assert-is-complex128array' ); -var isBooleanArray = require( '@stdlib/assert-is-booleanarray' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var ctors = require( '@stdlib/array-typed-ctors' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var resolveSetter = require( '@stdlib/array-base-resolve-setter' ); -var ARRAY_DEFAULTS = require( '@stdlib/array-defaults' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil = require( '@stdlib/math-base-special-ceil' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); -var log2 = require( '@stdlib/math-base-special-log2' ); -var min = require( '@stdlib/math-base-special-min' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var createPool = require( './pool.js' ); -var BYTES_PER_ELEMENT = require( './bytes_per_element.json' ); - - -// VARIABLES // - -var DEFAULT_DTYPE = ARRAY_DEFAULTS.get( 'dtypes.default' ); -var Complex64Array = ctors( 'complex64' ); -var Complex128Array = ctors( 'complex128' ); -var BooleanArray = ctors( 'bool' ); - - -// FUNCTIONS // - -/** -* Tests whether an array is a single-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a single-precision complex floating-point number array -*/ -function isCmplx64Array( arr ) { - return ( arr instanceof Complex64Array ); -} - -/** -* Tests whether an array is a double-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a double-precision complex floating-point number array -*/ -function isCmplx128Array( arr ) { - return ( arr instanceof Complex128Array ); -} - -/** -* Tests whether an array is a boolean array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a boolean array -*/ -function isBoolArray( arr ) { - return ( arr instanceof BooleanArray ); -} - - -// MAIN // - -/** -* Creates a typed array pool. -* -* @param {Options} [options] - pool options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} allocator -* -* @example -* var typedarraypool = factory(); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -function factory( options ) { - var nbytes; - var pool; - var opts; - var err; - - opts = defaults(); - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - pool = createPool( ceil( log2( opts.highWaterMark ) ) ); - nbytes = 0; - - setReadOnly( malloc, 'malloc', malloc ); // circular reference - setReadOnly( malloc, 'calloc', calloc ); - setReadOnly( malloc, 'free', free ); - setReadOnly( malloc, 'clear', clear ); - setReadOnly( malloc, 'highWaterMark', opts.highWaterMark ); - setReadOnlyAccessor( malloc, 'nbytes', getBytes ); - - return malloc; - - /** - * Returns the number of allocated bytes. - * - * @private - * @returns {NonNegativeInteger} number of allocated bytes - */ - function getBytes() { - return nbytes; - } - - /** - * Returns an array buffer. - * - * @private - * @param {NonNegativeInteger} n - number of bytes - * @returns {(ArrayBuffer|null)} array buffer or null - */ - function arraybuffer( n ) { - var buf; - var i; - - // Convert the number of bytes to an index in our pool table: - i = log2( n ); - - // If we already have an available array buffer, use it... - if ( i < pool.length && pool[ i ].length ) { - return pool[ i ].pop(); - } - // Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate... - if ( nbytes+n > opts.highWaterMark ) { - return null; - } - buf = new ArrayBuffer( n ); - - // Update the running counter of allocated bytes: - nbytes += n; - - return buf; - } - - /** - * Returns a typed array. - * - * @private - * @param {Function} ctor - typed array constructor - * @param {NonNegativeInteger} len - view length - * @param {string} dtype - data type - * @returns {(TypedArray|null)} typed array or null - */ - function typedarray( ctor, len, dtype ) { - var buf; - if ( len === 0 ) { - return new ctor( 0 ); - } - buf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] ); - if ( buf === null ) { - return buf; - } - return new ctor( buf, 0, len ); - } - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length or an array-like object - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function malloc() { - var nargs; - var dtype; - var ctor; - var arr; - var out; - var set; - var get; - var len; - var i; - - nargs = arguments.length; - if ( nargs && isString( arguments[ nargs-1 ] ) ) { - nargs -= 1; - dtype = arguments[ nargs ]; - } else { - dtype = DEFAULT_DTYPE; - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( '01H2Y', dtype ) ); - } - if ( nargs <= 0 ) { - return new ctor( 0 ); - } - // Check if provided a typed array length... - if ( isNonNegativeInteger( arguments[ 0 ] ) ) { - return typedarray( ctor, arguments[ 0 ], dtype ); - } - // Check if provided an array-like object containing data elements... - if ( isCollection( arguments[ 0 ] ) ) { - arr = arguments[ 0 ]; - len = arr.length; - if ( isComplex128Array( arr ) ) { - arr = reinterpret128( arr, 0 ); - } else if ( isComplex64Array( arr ) ) { - arr = reinterpret64( arr, 0 ); - } else if ( isBooleanArray( arr ) ) { - arr = reinterpretBoolean( arr, 0 ); - } else if ( isComplexDataType( dtype ) ) { - // Assume we've been provided an array of interleaved real and imaginary components... - len /= 2; - } - out = typedarray( ctor, len, dtype ); - if ( out === null ) { - return out; - } - if ( isCmplx128Array( out ) || isCmplx64Array( out ) || isBoolArray( out ) ) { - out.set( arr ); - return out; - } - // Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other "unsafe" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things... - get = resolveGetter( arr ); - set = resolveSetter( out ); - for ( i = 0; i < len; i++ ) { - set( out, i, get( arr, i ) ); - } - return out; - } - throw new TypeError( format( '01H2r', arguments[ 0 ] ) ); - } - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {NonNegativeInteger} [len=0] - array length - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function calloc() { - var nargs; - var out; - var tmp; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - out = malloc(); - } else if ( nargs === 1 ) { - out = malloc( arguments[ 0 ] ); - } else { - out = malloc( arguments[ 0 ], arguments[ 1 ] ); - } - if ( out !== null ) { - // Initialize the memory... - if ( isCmplx128Array( out ) ) { - tmp = reinterpret128( out, 0 ); - } else if ( isCmplx64Array( out ) ) { - tmp = reinterpret64( out, 0 ); - } else if ( isBoolArray( out ) ) { - tmp = reinterpretBoolean( out, 0 ); - } else { - tmp = out; - } - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = 0.0; - } - } - return out; - } - - /** - * Frees a typed array or typed array buffer. - * - * ## Notes - * - * - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., "freeing" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool. - * - * @private - * @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free - * @throws {TypeError} must provide a typed array or typed array buffer - * @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed - */ - function free( buf ) { - var n; - var p; - var i; - if ( isTypedArrayLike( buf ) && buf.buffer ) { - buf = buf.buffer; - } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( '01H2s', buf ) ); - } - if ( buf.byteLength > 0 ) { - n = floor( log2( buf.byteLength ) ); - - // Prohibit "freeing" array buffers which would potentially allow users to circumvent high water mark limits: - n = min( pool.length-1, n ); - - // Ensure that we do not attempt to free the same buffer more than once... - p = pool[ n ]; - for ( i = 0; i < p.length; i++ ) { - if ( p[ i ] === buf ) { - return false; - } - } - // Add the buffer to our pool of free buffers: - p.push( buf ); - } - return true; - } - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @private - */ - function clear() { - var i; - for ( i = 0; i < pool.length; i++ ) { - pool[ i ].length = 0; - } - nbytes = 0; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6c12a4e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Typed array pool. -* -* @module @stdlib/array-pool -* -* @example -* var typedarraypool = require( '@stdlib/array-pool' ); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8f69ee3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,63 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @name typedarraypool -* @type {Function} -* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a valid array length or an array-like object -* @throws {TypeError} must provide a recognized data type -* @returns {(TypedArray|null)} typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -var typedarraypool = factory(); - - -// EXPORTS // - -module.exports = typedarraypool; diff --git a/lib/pool.js b/lib/pool.js deleted file mode 100644 index 5abd287..0000000 --- a/lib/pool.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Initializes a cache for pooled typed array buffers. -* -* @private -* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size -* @returns {ArrayArray} initialized cache -*/ -function pool( n ) { - var out; - var i; - - out = []; - for ( i = 0; i < n+1; i++ ) { - out.push( [] ); - } - return out; -} - - -// EXPORTS // - -module.exports = pool; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index da746bb..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'highWaterMark': 1024 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '01H2V', options ) ); - } - if ( hasOwnProp( options, 'highWaterMark' ) ) { - opts.highWaterMark = options.highWaterMark; - if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 994a553..ce31461 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Typed array pool.", "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,83 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-is-complex-floating-point-data-type": "^0.2.1", - "@stdlib/array-base-resolve-getter": "^0.2.1", - "@stdlib/array-base-resolve-setter": "^0.2.1", - "@stdlib/array-buffer": "^0.2.1", - "@stdlib/array-defaults": "^0.2.1", - "@stdlib/array-typed-ctors": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-arraybuffer": "^0.2.1", - "@stdlib/assert-is-booleanarray": "^0.0.1", - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-complex128array": "^0.2.1", - "@stdlib/assert-is-complex64array": "^0.2.1", - "@stdlib/assert-is-nonnegative-integer": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/assert-is-string": "^0.2.1", - "@stdlib/assert-is-typed-array-like": "^0.2.1", - "@stdlib/math-base-special-ceil": "^0.2.1", - "@stdlib/math-base-special-ceil2": "^0.2.1", - "@stdlib/math-base-special-floor": "^0.2.2", - "@stdlib/math-base-special-log2": "^0.2.1", - "@stdlib/math-base-special-min": "^0.2.2", - "@stdlib/strided-base-reinterpret-boolean": "^0.0.1", - "@stdlib/strided-base-reinterpret-complex128": "^0.2.1", - "@stdlib/strided-base-reinterpret-complex64": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-bool": "^0.0.1", - "@stdlib/array-complex128": "^0.2.1", - "@stdlib/array-complex64": "^0.2.1", - "@stdlib/array-float32": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/array-int16": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/array-int8": "^0.2.1", - "@stdlib/array-uint16": "^0.2.1", - "@stdlib/array-uint32": "^0.2.1", - "@stdlib/array-uint8": "^0.2.1", - "@stdlib/array-uint8c": "^0.2.1", - "@stdlib/assert-instance-of": "^0.2.1", - "@stdlib/assert-is-complex-typed-array": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-typed-array": "^0.2.1", - "@stdlib/boolean-ctor": "^0.2.1", - "@stdlib/complex-float32-ctor": "^0.0.1", - "@stdlib/complex-float64-ctor": "^0.0.1", - "@stdlib/complex-imag": "^0.2.1", - "@stdlib/complex-imagf": "^0.2.1", - "@stdlib/complex-real": "^0.2.1", - "@stdlib/complex-realf": "^0.2.1", - "@stdlib/math-base-special-pow": "^0.2.1", - "@stdlib/random-base-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9bac0b8 --- /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.factory.js b/test/test.factory.js deleted file mode 100644 index 7344c01..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,2401 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function (no options)', function test( t ) { - t.strictEqual( typeof factory(), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - t.strictEqual( typeof factory( {} ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided a `highWaterMark` option which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (length)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a function which returns a typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=bool)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, length)', function test( t ) { - var typedarraypool = factory(); - var arr; - - arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=bool, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=bool, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ true, false, false, true ]; - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( v, arr[ 0 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( v, arr[ 1 ], 'returns expected value' ); - - v = out.get( 2 ); - t.strictEqual( v, arr[ 2 ], 'returns expected value' ); - - v = out.get( 3 ); - t.strictEqual( v, arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=bool, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Uint8Array( 0 ); - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8Array( [ 1, 0, 0, 1 ] ); - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( v, true, 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( v, false, 'returns expected value' ); - - v = out.get( 2 ); - t.strictEqual( v, false, 'returns expected value' ); - - v = out.get( 3 ); - t.strictEqual( v, true, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a `malloc` method which is a circular reference', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=bool)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=bool, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'bool' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( Boolean( i%2 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( v, false, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - var buf; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the returned function is a property which returns the pool\'s high water mark', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function supports specifying a high water mark which limits the total amount of memory a pool can allocate', function test( t ) { - var typedarraypool; - var arr1; - var arr2; - - typedarraypool = factory({ - 'highWaterMark': 64 // bytes - }); - - typedarraypool.clear(); - - arr1 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr1.length, 8, 'returns expected value' ); - t.strictEqual( arr1.byteLength, 64, 'returns expected value' ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - typedarraypool.free( arr1 ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Create an array which is less than or equal to the high water mark: - arr2 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr2.length, 8, 'returns expected value' ); - t.strictEqual( arr2.byteLength, 64, 'returns expected value' ); - - typedarraypool.free( arr2 ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a property which returns the total number of accumulated bytes', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var typedarraypool; - var arrs; - var i; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index e60c54f..0000000 --- a/test/test.js +++ /dev/null @@ -1,1935 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var typedarraypool = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=bool)', function test( t ) { - var arr = typedarraypool( 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=bool, length)', function test( t ) { - var arr = typedarraypool( 10, 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=bool, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ true, false, false, true ]; - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( v, arr[ 0 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( v, arr[ 1 ], 'returns expected value' ); - - v = out.get( 2 ); - t.strictEqual( v, arr[ 2 ], 'returns expected value' ); - - v = out.get( 3 ); - t.strictEqual( v, arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=bool, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Uint8Array( 0 ); - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8Array( [ 1, 0, 0, 1 ] ); - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( v, true, 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( v, false, 'returns expected value' ); - - v = out.get( 2 ); - t.strictEqual( v, false, 'returns expected value' ); - - v = out.get( 3 ); - t.strictEqual( v, true, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=bool)', function test( t ) { - var arr = typedarraypool.calloc( 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=bool, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'bool' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( Boolean( i%2 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( v, false, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -}); From 9e73969b8583aadf633d8bb6026e8d58931ab06f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 7 Jul 2024 17:03:01 +0000 Subject: [PATCH 092/103] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index ce4ba27..7f297ce 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -38,7 +38,7 @@ var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); var resolveSetter = require( '@stdlib/array-base-resolve-setter' ); var ARRAY_DEFAULTS = require( '@stdlib/array-defaults' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ArrayBuffer = require( '@stdlib/array-buffer' ); var ceil = require( '@stdlib/math-base-special-ceil' ); var floor = require( '@stdlib/math-base-special-floor' ); @@ -243,7 +243,7 @@ function factory( options ) { } ctor = ctors( dtype ); if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '01H2Y', dtype ) ); } if ( nargs <= 0 ) { return new ctor( 0 ); @@ -282,7 +282,7 @@ function factory( options ) { } return out; } - throw new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) ); + throw new TypeError( format( '01H2r', arguments[ 0 ] ) ); } /** @@ -350,7 +350,7 @@ function factory( options ) { if ( isTypedArrayLike( buf ) && buf.buffer ) { buf = buf.buffer; } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) ); + throw new TypeError( format( '01H2s', buf ) ); } if ( buf.byteLength > 0 ) { n = floor( log2( buf.byteLength ) ); diff --git a/lib/validate.js b/lib/validate.js index ce54890..da746bb 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '01H2V', options ) ); } if ( hasOwnProp( options, 'highWaterMark' ) ) { opts.highWaterMark = options.highWaterMark; if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) ); + return new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) ); } } return null; diff --git a/package.json b/package.json index c4ee0d8..994a553 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "@stdlib/strided-base-reinterpret-boolean": "^0.0.1", "@stdlib/strided-base-reinterpret-complex128": "^0.2.1", "@stdlib/strided-base-reinterpret-complex64": "^0.2.0", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", From 4d22507defe491be973cad2e0cd46cf666dd68ab Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 7 Jul 2024 17:09:42 +0000 Subject: [PATCH 093/103] Remove files --- index.d.ts | 359 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5206 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 8298bf3..0000000 --- a/index.d.ts +++ /dev/null @@ -1,359 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike, RealOrComplexTypedArray, BooleanArray, NumericDataType as DataType } from '@stdlib/types/array'; -import ArrayBuffer = require( '@stdlib/array-buffer' ); - -/** -* Typed array or null. -*/ -type TypedArrayOrNull = RealOrComplexTypedArray | BooleanArray | null; - -/** -* Interface defining pool options. -*/ -interface Options { - /** - * Maximum total memory which can be allocated. - */ - highWaterMark?: number; -} - -/** -* Pool interface. -*/ -interface Pool { - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr = typedarraypool(); - * // returns [] - * - * @example - * var arr = typedarraypool( 'float32' ); - * // returns [] - */ - ( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * // Allocate an array of doubles: - * var arr = typedarraypool( 5, 'float64' ); - * // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * typedarraypool.free( arr ); - * - * @example - * var arr1 = typedarraypool( [ 0.5, 0.5, 0.5 ] ); - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * @example - * var arr1 = [ 0.5, 0.5, 0.5 ]; - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - */ - ( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc(); - * // returns [] - * - * var arr2 = typedarraypool.calloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param length - typed array length - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc( 5 ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * var arr2 = typedarraypool.calloc( 5, 'uint8' ); - * // returns [ 0, 0, 0, 0, 0 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( length: number, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc(); - * // returns [] - * - * var arr2 = typedarraypool.malloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc( 5 ); - * // returns - * - * var arr2 = typedarraypool.malloc( 5, 'uint8' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 5.0, -3.0, 2.0 ] ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr2 = typedarraypool.malloc( arr1 ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr3 = typedarraypool.malloc( arr1, 'int32' ); - * // returns [ 5, -3, 2 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * typedarraypool.free( arr3 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ] ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * var arr2 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ], 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Frees a typed array or typed array buffer for use in a future allocation. - * - * @param buf - typed array or typed array buffer to free - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array for use in a future allocation: - * typedarraypool.free( arr ); - * - * // Create another typed array: - * arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array buffer for use in a future allocation: - * typedarraypool.free( arr.buffer ); - */ - free( buf: RealOrComplexTypedArray | BooleanArray | ArrayBuffer ): void; - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr ); - * - * // ... - * - * // Clear all freed buffers: - * typedarraypool.clear(); - */ - clear(): void; - - /** - * Read-only property returning the pool's high water mark. - * - * ## Notes - * - * - Once a high water mark is reached, typed array allocation fails. - * - * @example - * var limit = typedarraypool.highWaterMark; - * // returns - */ - readonly highWaterMark: number; - - /** - * Read-only property returning the total number of allocated bytes. - * - * @example - * var arr = typedarraypool( 5, 'float64' ); - * - * var nbytes = typedarraypool.nbytes; - * // returns - */ - readonly nbytes: number; - - /** - * Creates a typed array pool. - * - * @param options - pool options - * @param options.highWaterMark - maximum total memory which can be allocated - * @throws must provide valid options - * @returns allocator - * - * @example - * var allocator = typedarraypool.factory(); - * - * // Allocate an array of doubles: - * var arr = allocator( 5, 'float64' ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * allocator.free( arr ); - */ - factory( options?: Options ): Pool; -} - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @param arg - an array length or an array-like object -* @param dtype - data type (default: 'float64') -* @returns typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -declare var typedarraypool: Pool; - - -// EXPORTS // - -export = typedarraypool; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 1857d00..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-booleanarray@v0.0.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.2.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.2.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.1-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-setter@v0.2.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/array-defaults@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.1-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.2.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.2.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.2.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.2.1-esm/index.mjs";import M from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.2.2-esm/index.mjs";import W from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";var H={bool:1,float64:8,float32:4,int16:2,int32:4,int8:1,uint16:2,uint32:4,uint8:1,uint8c:1,complex64:8,complex128:16},T=g.get("dtypes.default"),L=h("complex64"),P=h("complex128"),V=h("bool");function Y(e){return e instanceof L}function q(e){return e instanceof P}function z(e){return e instanceof V}function A(g){var L,P,V,A;if(V={highWaterMark:9007199254740992},arguments.length&&(A=function(e,t){return W(t)?E(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(u("01H2t","highWaterMark",e.highWaterMark)):null:new TypeError(u("01H2V",t))}(V,g),A))throw A;return P=function(e){var t,r;for(t=[],r=0;r0){for(t=y(k(e.byteLength)),t=M(P.length-1,t),r=P[t],s=0;sV.highWaterMark?null:(t=new b(e),L+=e,t)}(w(t)*H[r]))?s:new e(s,0,t)}function C(){var e,i,n,a,g,b,x,y,w;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:T,null===(n=h(i)))throw new TypeError(u("01H2Y",i));if(e<=0)return new n(0);if(r(arguments[0]))return B(n,arguments[0],i);if(s(arguments[0])){if(y=(a=arguments[0]).length,d(a)?a=j(a,0):m(a)?a=p(a,0):l(a)?a=f(a,0):o(i)&&(y/=2),null===(g=B(n,y,i)))return g;if(q(g)||Y(g)||z(g))return g.set(a),g;for(x=c(a),b=v(g),w=0;w[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '01H2Y', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( isBooleanArray( arr ) ) {\n\t\t\t\tarr = reinterpretBoolean( arr, 0 );\n\t\t\t} else if ( isComplexDataType( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) || isBoolArray( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = resolveGetter( arr );\n\t\t\tset = resolveSetter( out );\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '01H2r', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else if ( isBoolArray( out ) ) {\n\t\t\t\ttmp = reinterpretBoolean( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( '01H2s', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'highWaterMark': 1024\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '01H2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'highWaterMark' ) ) {\n\t\topts.highWaterMark = options.highWaterMark;\n\t\tif ( !isNonNegativeInteger( opts.highWaterMark ) ) {\n\t\t\treturn new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Initializes a cache for pooled typed array buffers.\n*\n* @private\n* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size\n* @returns {ArrayArray} initialized cache\n*/\nfunction pool( n ) {\n\tvar out;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < n+1; i++ ) {\n\t\tout.push( [] );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default pool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DEFAULT_DTYPE","ARRAY_DEFAULTS","get","Complex64Array","ctors","Complex128Array","BooleanArray","isCmplx64Array","arr","isCmplx128Array","isBoolArray","factory","options","nbytes","pool","opts","err","highWaterMark","arguments","length","isObject","hasOwnProp","isNonNegativeInteger","TypeError","format","validate","n","out","i","push","createPool","ceil","log2","setReadOnly","malloc","nargs","tmp","reinterpret128","reinterpret64","reinterpretBoolean","buf","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","setReadOnlyAccessor","typedarray","ctor","len","dtype","pop","ArrayBuffer","arraybuffer","ceil2","BYTES_PER_ELEMENT","set","isString","isCollection","isComplex128Array","isComplex64Array","isBooleanArray","isComplexDataType","resolveGetter","resolveSetter","typedarraypool","main"],"mappings":";;wzFAuDIA,EAAgBC,EAAeC,IAAK,kBACpCC,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cACzBE,EAAeF,EAAO,QAY1B,SAASG,EAAgBC,GACxB,OAASA,aAAeL,CACzB,CASA,SAASM,EAAiBD,GACzB,OAASA,aAAeH,CACzB,CASA,SAASK,EAAaF,GACrB,OAASA,aAAeF,CACzB,CA6BA,SAASK,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,EChGO,CACNE,cAAiB,kBDgGbC,UAAUC,SACdH,EElFF,SAAmBD,EAAMH,GACxB,OAAMQ,EAAUR,GAGXS,EAAYT,EAAS,mBACzBG,EAAKE,cAAgBL,EAAQK,eACvBK,EAAsBP,EAAKE,gBACzB,IAAIM,UAAWC,EAAQ,QAAS,gBAAiBT,EAAKE,gBAGxD,KARC,IAAIM,UAAWC,EAAQ,QAASZ,GASzC,CFuEQa,CAAUV,EAAMH,GACjBI,GACJ,MAAMA,EAaR,OAVAF,EG3GD,SAAeY,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,CHkGQG,CAAYC,EAAMC,EAAMjB,EAAKE,iBACpCJ,EAAS,EAEToB,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,UAiKrB,WACC,IAAIC,EACAR,EACAS,EACAR,EAEJO,EAAQjB,UAAUC,OAEjBQ,EADc,IAAVQ,EACED,IACe,IAAVC,EACLD,EAAQhB,UAAW,IAEnBgB,EAAQhB,UAAW,GAAKA,UAAW,IAE1C,GAAa,OAARS,EAWJ,IARCS,EADI3B,EAAiBkB,GACfU,EAAgBV,EAAK,GAChBpB,EAAgBoB,GACrBW,EAAeX,EAAK,GACfjB,EAAaiB,GAClBY,EAAoBZ,EAAK,GAEzBA,EAEDC,EAAI,EAAGA,EAAIQ,EAAIjB,OAAQS,IAC5BQ,EAAKR,GAAM,EAGb,OAAOD,CACP,IA9LDM,EAAaC,EAAQ,QA4MrB,SAAeM,GACd,IAAId,EACAe,EACAb,EACJ,GAAKc,EAAkBF,IAASA,EAAIG,OACnCH,EAAMA,EAAIG,YACJ,IAAMC,EAAeJ,GAC3B,MAAM,IAAIjB,UAAWC,EAAQ,QAASgB,IAEvC,GAAKA,EAAIK,WAAa,EAAI,CAQzB,IAPAnB,EAAIoB,EAAOd,EAAMQ,EAAIK,aAGrBnB,EAAIqB,EAAKjC,EAAKK,OAAO,EAAGO,GAGxBe,EAAI3B,EAAMY,GACJE,EAAI,EAAGA,EAAIa,EAAEtB,OAAQS,IAC1B,GAAKa,EAAGb,KAAQY,EACf,OAAO,EAITC,EAAEZ,KAAMW,EACR,CACD,OAAO,CACP,IArODP,EAAaC,EAAQ,SA4OrB,WACC,IAAIN,EACJ,IAAMA,EAAI,EAAGA,EAAId,EAAKK,OAAQS,IAC7Bd,EAAMc,GAAIT,OAAS,EAEpBN,EAAS,CACT,IAjPDoB,EAAaC,EAAQ,gBAAiBnB,EAAKE,eAC3C+B,EAAqBd,EAAQ,UAU7B,WACC,OAAOrB,CACP,IAVMqB,EAmDP,SAASe,EAAYC,EAAMC,EAAKC,GAC/B,IAAIZ,EACJ,OAAa,IAARW,EACG,IAAID,EAAM,GAGL,QADbV,EArCD,SAAsBd,GACrB,IAAIc,EACAZ,EAMJ,OAHAA,EAAII,EAAMN,IAGDZ,EAAKK,QAAUL,EAAMc,GAAIT,OAC1BL,EAAMc,GAAIyB,MAGbxC,EAAOa,EAAIX,EAAKE,cACb,MAERuB,EAAM,IAAIc,EAAa5B,GAGvBb,GAAUa,EAEHc,EACP,CAgBMe,CAAaC,EAAOL,GAAMM,EAAmBL,KAE3CZ,EAED,IAAIU,EAAMV,EAAK,EAAGW,EACzB,CAkBD,SAASjB,IACR,IAAIC,EACAiB,EACAF,EACA1C,EACAmB,EACA+B,EACAxD,EACAiD,EACAvB,EAUJ,GALCwB,GAHDjB,EAAQjB,UAAUC,SACJwC,EAAUzC,UAAWiB,EAAM,IAEhCjB,UADRiB,GAAS,GAGDnC,EAGK,QADdkD,EAAO9C,EAAOgD,IAEb,MAAM,IAAI7B,UAAWC,EAAQ,QAAS4B,IAEvC,GAAKjB,GAAS,EACb,OAAO,IAAIe,EAAM,GAGlB,GAAK5B,EAAsBJ,UAAW,IACrC,OAAO+B,EAAYC,EAAMhC,UAAW,GAAKkC,GAG1C,GAAKQ,EAAc1C,UAAW,IAAQ,CAcrC,GAZAiC,GADA3C,EAAMU,UAAW,IACPC,OACL0C,EAAmBrD,GACvBA,EAAM6B,EAAgB7B,EAAK,GAChBsD,EAAkBtD,GAC7BA,EAAM8B,EAAe9B,EAAK,GACfuD,EAAgBvD,GAC3BA,EAAM+B,EAAoB/B,EAAK,GACpBwD,EAAmBZ,KAE9BD,GAAO,GAGK,QADbxB,EAAMsB,EAAYC,EAAMC,EAAKC,IAE5B,OAAOzB,EAER,GAAKlB,EAAiBkB,IAASpB,EAAgBoB,IAASjB,EAAaiB,GAEpE,OADAA,EAAI+B,IAAKlD,GACFmB,EAKR,IAFAzB,EAAM+D,EAAezD,GACrBkD,EAAMQ,EAAevC,GACfC,EAAI,EAAGA,EAAIuB,EAAKvB,IACrB8B,EAAK/B,EAAKC,EAAG1B,EAAKM,EAAKoB,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,QAASN,UAAW,IACjD,CAoGF,CIxUG,IAACiD,EAAiBxD,ICPrBsB,EAAAmC,EAAA,UAAAzD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9bac0b8..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 497ec5310204b48ce78a433ba2d034a086bb0c99 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 7 Jul 2024 17:10:09 +0000 Subject: [PATCH 094/103] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 135 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.calloc.js | 265 -- benchmark/benchmark.factory.js | 71 - benchmark/benchmark.js | 265 -- benchmark/benchmark.length.bool.js | 102 - benchmark/benchmark.length.complex128.js | 102 - benchmark/benchmark.length.complex64.js | 102 - benchmark/benchmark.length.float32.js | 102 - benchmark/benchmark.length.float64.js | 102 - benchmark/benchmark.length.int16.js | 102 - benchmark/benchmark.length.int32.js | 102 - benchmark/benchmark.length.int8.js | 102 - benchmark/benchmark.length.uint16.js | 102 - benchmark/benchmark.length.uint32.js | 102 - benchmark/benchmark.length.uint8.js | 102 - benchmark/benchmark.length.uint8c.js | 102 - benchmark/benchmark.malloc.js | 265 -- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 53 - dist/index.js.map | 7 - docs/repl.txt | 333 -- docs/types/test.ts | 193 - examples/index.js | 80 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/bytes_per_element.json | 14 - lib/defaults.js | 42 - lib/factory.js | 391 -- lib/index.js | 56 - lib/main.js | 63 - lib/pool.js | 44 - lib/validate.js | 66 - package.json | 104 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 2401 ---------- test/test.js | 1935 -------- 63 files changed, 4872 insertions(+), 11301 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.calloc.js delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.bool.js delete mode 100644 benchmark/benchmark.length.complex128.js delete mode 100644 benchmark/benchmark.length.complex64.js delete mode 100644 benchmark/benchmark.length.float32.js delete mode 100644 benchmark/benchmark.length.float64.js delete mode 100644 benchmark/benchmark.length.int16.js delete mode 100644 benchmark/benchmark.length.int32.js delete mode 100644 benchmark/benchmark.length.int8.js delete mode 100644 benchmark/benchmark.length.uint16.js delete mode 100644 benchmark/benchmark.length.uint32.js delete mode 100644 benchmark/benchmark.length.uint8.js delete mode 100644 benchmark/benchmark.length.uint8c.js delete mode 100644 benchmark/benchmark.malloc.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/bytes_per_element.json delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/pool.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ea35f20..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/array/pool) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6f7c875..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/array/pool) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 869c4e9..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f92a6c5..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -481,7 +478,7 @@ console.log( 'nbytes: %d', typedarray.nbytes ); ## 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]. @@ -548,11 +545,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-arraybuffer]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer -[@stdlib/array/typed-dtypes]: https://github.com/stdlib-js/array-typed-dtypes +[@stdlib/array/typed-dtypes]: https://github.com/stdlib-js/array-typed-dtypes/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/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.calloc.js b/benchmark/benchmark.calloc.js deleted file mode 100644 index 2a04c65..0000000 --- a/benchmark/benchmark.calloc.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var isBooleanArray = require( '@stdlib/assert-is-booleanarray' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':calloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=bool', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'bool' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isBooleanArray( arr ) ) { - b.fail( 'should return a boolean array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 58918bb..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = typedarray.factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:highWaterMark', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'highWaterMark': 0 - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.highWaterMark = i; - f = typedarray.factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 46c6397..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var isBooleanArray = require( '@stdlib/assert-is-booleanarray' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=bool', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'bool' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isBooleanArray( arr ) ) { - b.fail( 'should return a boolean array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.bool.js b/benchmark/benchmark.length.bool.js deleted file mode 100644 index d9ad47b..0000000 --- a/benchmark/benchmark.length.bool.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isBooleanArray = require( '@stdlib/assert-is-booleanarray' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'bool' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isBooleanArray( arr ) ) { - b.fail( 'should return a boolean array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=bool,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=bool,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=bool,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex128.js b/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 12c6668..0000000 --- a/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex64.js b/benchmark/benchmark.length.complex64.js deleted file mode 100644 index ca2b45c..0000000 --- a/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float32.js b/benchmark/benchmark.length.float32.js deleted file mode 100644 index b3b4508..0000000 --- a/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float64.js b/benchmark/benchmark.length.float64.js deleted file mode 100644 index 5f0132d..0000000 --- a/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int16.js b/benchmark/benchmark.length.int16.js deleted file mode 100644 index 9f253cb..0000000 --- a/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int32.js b/benchmark/benchmark.length.int32.js deleted file mode 100644 index f83e795..0000000 --- a/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int8.js b/benchmark/benchmark.length.int8.js deleted file mode 100644 index 5b01174..0000000 --- a/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint16.js b/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 32b0a5d..0000000 --- a/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint32.js b/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 290b90c..0000000 --- a/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8.js b/benchmark/benchmark.length.uint8.js deleted file mode 100644 index ff7d733..0000000 --- a/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8c.js b/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index 8f0d10a..0000000 --- a/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.malloc.js b/benchmark/benchmark.malloc.js deleted file mode 100644 index c85d2fb..0000000 --- a/benchmark/benchmark.malloc.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var isBooleanArray = require( '@stdlib/assert-is-booleanarray' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':malloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=bool', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'bool' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isBooleanArray( arr ) ) { - b.fail( 'should return a boolean array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 612de17..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/array/pool" -%% click B href "https://github.com/stdlib-js/array-pool/tree/main" -%% click C href "https://github.com/stdlib-js/array-pool/tree/production" -%% click D href "https://github.com/stdlib-js/array-pool/tree/esm" -%% click E href "https://github.com/stdlib-js/array-pool/tree/deno" -%% click F href "https://github.com/stdlib-js/array-pool/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/pool -[production-url]: https://github.com/stdlib-js/array-pool/tree/production -[deno-url]: https://github.com/stdlib-js/array-pool/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-pool/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-pool/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-pool/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-pool/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-pool/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 5160b6f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import typedarraypool from '../docs/types/index'; -export = typedarraypool; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 925147b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,53 +0,0 @@ -"use strict";var s=function(n,i){return function(){return i||n((i={exports:{}}).exports,i),i.exports}};var M=s(function(Cr,w){"use strict";function z(){return{highWaterMark:9007199254740992}}w.exports=z});var T=s(function(Or,E){"use strict";var G=require("@stdlib/assert-is-plain-object"),H=require("@stdlib/assert-has-own-property"),J=require("@stdlib/assert-is-nonnegative-integer").isPrimitive,k=require("@stdlib/string-format");function K(n,i){return G(i)?H(i,"highWaterMark")&&(n.highWaterMark=i.highWaterMark,!J(n.highWaterMark))?new TypeError(k("invalid option. `%s` option must be a nonnegative integer. Option: `%s`.","highWaterMark",n.highWaterMark)):null:new TypeError(k("invalid argument. Options argument must be an object. Value: `%s`.",i))}E.exports=K});var B=s(function(Pr,W){"use strict";function Q(n){var i,u;for(i=[],u=0;uv.highWaterMark?null:(e=new fr(r),i+=r,e)}function d(r,e,t){var a;return e===0?new r(0):(a=F(pr(e)*dr[t]),a===null?a:new r(a,0,e))}function o(){var r,e,t,a,l,A,x,c,f;if(r=arguments.length,r&&Z(arguments[r-1])?(r-=1,e=arguments[r]):e=Ar,t=p(e),t===null)throw new TypeError(y("invalid argument. Must provide a recognized data type. Value: `%s`.",e));if(r<=0)return new t(0);if($(arguments[0]))return d(t,arguments[0],e);if(rr(arguments[0])){if(a=arguments[0],c=a.length,nr(a)?a=O(a,0):ir(a)?a=C(a,0):ur(a)?a=P(a,0):tr(e)&&(c/=2),l=d(t,c,e),l===null)return l;if(R(l)||L(l)||N(l))return l.set(a),l;for(x=lr(a),A=sr(l),f=0;f0){for(e=cr(m(r.byteLength)),e=hr(u.length-1,e),t=u[e],a=0;a[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( isBooleanArray( arr ) ) {\n\t\t\t\tarr = reinterpretBoolean( arr, 0 );\n\t\t\t} else if ( isComplexDataType( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) || isBoolArray( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = resolveGetter( arr );\n\t\t\tset = resolveSetter( out );\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else if ( isBoolArray( out ) ) {\n\t\t\t\ttmp = reinterpretBoolean( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nmodule.exports = typedarraypool;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* var typedarraypool = require( '@stdlib/array-pool' );\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,cAAiB,gBAClB,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,eAAgB,IACzCD,EAAK,cAAgBC,EAAQ,cACxB,CAACJ,EAAsBG,EAAK,aAAc,GACvC,IAAI,UAAWF,EAAQ,2EAA4E,gBAAiBE,EAAK,aAAc,CAAE,EAG3I,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cA6BA,SAASC,EAAM,EAAI,CAClB,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAI,EAAE,EAAGA,IACrBD,EAAI,KAAM,CAAC,CAAE,EAEd,OAAOA,CACR,CAKAF,EAAO,QAAUC,IC3CjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,KAAQ,EACR,QAAW,EACX,QAAW,EACX,MAAS,EACT,MAAS,EACT,KAAQ,EACR,OAAU,EACV,OAAU,EACV,MAAS,EACT,OAAU,EACT,UAAa,EACb,WAAc,EAChB,ICbA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,GAAe,QAAS,8BAA+B,EACvDC,GAAmB,QAAS,oCAAqC,EACjEC,GAAgB,QAAS,+BAAgC,EACzDC,GAAoB,QAAS,+DAAgE,EAC7FC,GAAmB,QAAS,kCAAmC,EAC/DC,GAAoB,QAAS,mCAAoC,EACjEC,GAAiB,QAAS,gCAAiC,EAC3DC,EAAc,QAAS,uDAAwD,EAC/EC,GAAsB,QAAS,uDAAwD,EACvFC,EAAQ,QAAS,2BAA4B,EAC7CC,EAAgB,QAAS,4CAA6C,EACtEC,EAAiB,QAAS,6CAA8C,EACxEC,EAAqB,QAAS,0CAA2C,EACzEC,GAAgB,QAAS,mCAAoC,EAC7DC,GAAgB,QAAS,mCAAoC,EAC7DC,GAAiB,QAAS,wBAAyB,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,GAAc,QAAS,sBAAuB,EAC9CC,GAAO,QAAS,gCAAiC,EACjDC,GAAQ,QAAS,iCAAkC,EACnDC,GAAQ,QAAS,iCAAkC,EACnDC,EAAO,QAAS,gCAAiC,EACjDC,GAAM,QAAS,+BAAgC,EAC/CC,GAAW,IACXC,GAAW,IACXC,GAAa,IACbC,GAAoB,IAKpBC,GAAgBZ,GAAe,IAAK,gBAAiB,EACrDa,GAAiBnB,EAAO,WAAY,EACpCoB,GAAkBpB,EAAO,YAAa,EACtCqB,GAAerB,EAAO,MAAO,EAYjC,SAASsB,EAAgBC,EAAM,CAC9B,OAASA,aAAeJ,EACzB,CASA,SAASK,EAAiBD,EAAM,CAC/B,OAASA,aAAeH,EACzB,CASA,SAASK,EAAaF,EAAM,CAC3B,OAASA,aAAeF,EACzB,CA6BA,SAASK,GAASC,EAAU,CAC3B,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,EAAOhB,GAAS,EACX,UAAU,SACdiB,EAAMhB,GAAUe,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAAF,EAAOb,GAAYP,GAAMG,EAAMkB,EAAK,aAAc,CAAE,CAAE,EACtDF,EAAS,EAET9B,EAAakC,EAAQ,SAAUA,CAAO,EACtClC,EAAakC,EAAQ,SAAUC,CAAO,EACtCnC,EAAakC,EAAQ,OAAQE,CAAK,EAClCpC,EAAakC,EAAQ,QAASG,CAAM,EACpCrC,EAAakC,EAAQ,gBAAiBF,EAAK,aAAc,EACzD/B,GAAqBiC,EAAQ,SAAUI,CAAS,EAEzCJ,EAQP,SAASI,GAAW,CACnB,OAAOR,CACR,CASA,SAASS,EAAaC,EAAI,CACzB,IAAIC,EACAC,EAMJ,OAHAA,EAAI5B,EAAM0B,CAAE,EAGPE,EAAIX,EAAK,QAAUA,EAAMW,CAAE,EAAE,OAC1BX,EAAMW,CAAE,EAAE,IAAI,EAGjBZ,EAAOU,EAAIR,EAAK,cACb,MAERS,EAAM,IAAI/B,GAAa8B,CAAE,EAGzBV,GAAUU,EAEHC,EACR,CAWA,SAASE,EAAYC,EAAMC,EAAKC,EAAQ,CACvC,IAAIL,EACJ,OAAKI,IAAQ,EACL,IAAID,EAAM,CAAE,GAEpBH,EAAMF,EAAa1B,GAAOgC,CAAI,EAAE1B,GAAmB2B,CAAM,CAAE,EACtDL,IAAQ,KACLA,EAED,IAAIG,EAAMH,EAAK,EAAGI,CAAI,EAC9B,CAkBA,SAASX,GAAS,CACjB,IAAIa,EACAD,EACAF,EACAnB,EACAuB,EACAC,EACAC,EACAL,EACAH,EAUJ,GARAK,EAAQ,UAAU,OACbA,GAASxD,EAAU,UAAWwD,EAAM,CAAE,CAAE,GAC5CA,GAAS,EACTD,EAAQ,UAAWC,CAAM,GAEzBD,EAAQ1B,GAETwB,EAAO1C,EAAO4C,CAAM,EACfF,IAAS,KACb,MAAM,IAAI,UAAWnC,EAAQ,sEAAuEqC,CAAM,CAAE,EAE7G,GAAKC,GAAS,EACb,OAAO,IAAIH,EAAM,CAAE,EAGpB,GAAKpD,EAAsB,UAAW,CAAE,CAAE,EACzC,OAAOmD,EAAYC,EAAM,UAAW,CAAE,EAAGE,CAAM,EAGhD,GAAKrD,GAAc,UAAW,CAAE,CAAE,EAAI,CAcrC,GAbAgC,EAAM,UAAW,CAAE,EACnBoB,EAAMpB,EAAI,OACL3B,GAAmB2B,CAAI,EAC3BA,EAAMrB,EAAgBqB,EAAK,CAAE,EAClB5B,GAAkB4B,CAAI,EACjCA,EAAMtB,EAAesB,EAAK,CAAE,EACjB1B,GAAgB0B,CAAI,EAC/BA,EAAMpB,EAAoBoB,EAAK,CAAE,EACtB7B,GAAmBkD,CAAM,IAEpCD,GAAO,GAERG,EAAML,EAAYC,EAAMC,EAAKC,CAAM,EAC9BE,IAAQ,KACZ,OAAOA,EAER,GAAKtB,EAAiBsB,CAAI,GAAKxB,EAAgBwB,CAAI,GAAKrB,EAAaqB,CAAI,EACxE,OAAAA,EAAI,IAAKvB,CAAI,EACNuB,EAKR,IAFAE,EAAM5C,GAAemB,CAAI,EACzBwB,EAAM1C,GAAeyC,CAAI,EACnBN,EAAI,EAAGA,EAAIG,EAAKH,IACrBO,EAAKD,EAAKN,EAAGQ,EAAKzB,EAAKiB,CAAE,CAAE,EAE5B,OAAOM,CACR,CACA,MAAM,IAAI,UAAWvC,EAAQ,wGAAyG,UAAW,CAAE,CAAE,CAAE,CACxJ,CAgBA,SAAS0B,GAAS,CACjB,IAAIY,EACAC,EACAG,EACAT,EAUJ,GARAK,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAMd,EAAO,EACFa,IAAU,EACrBC,EAAMd,EAAQ,UAAW,CAAE,CAAE,EAE7Bc,EAAMd,EAAQ,UAAW,CAAE,EAAG,UAAW,CAAE,CAAE,EAEzCc,IAAQ,KAWZ,IATKtB,EAAiBsB,CAAI,EACzBG,EAAM/C,EAAgB4C,EAAK,CAAE,EAClBxB,EAAgBwB,CAAI,EAC/BG,EAAMhD,EAAe6C,EAAK,CAAE,EACjBrB,EAAaqB,CAAI,EAC5BG,EAAM9C,EAAoB2C,EAAK,CAAE,EAEjCG,EAAMH,EAEDN,EAAI,EAAGA,EAAIS,EAAI,OAAQT,IAC5BS,EAAKT,CAAE,EAAI,EAGb,OAAOM,CACR,CAcA,SAASZ,EAAMK,EAAM,CACpB,IAAID,EACAY,EACAV,EACJ,GAAKhD,GAAkB+C,CAAI,GAAKA,EAAI,OACnCA,EAAMA,EAAI,eACC,CAAC9C,GAAe8C,CAAI,EAC/B,MAAM,IAAI,UAAWhC,EAAQ,4EAA6EgC,CAAI,CAAE,EAEjH,GAAKA,EAAI,WAAa,EAAI,CAQzB,IAPAD,EAAI5B,GAAOE,EAAM2B,EAAI,UAAW,CAAE,EAGlCD,EAAIzB,GAAKgB,EAAK,OAAO,EAAGS,CAAE,EAG1BY,EAAIrB,EAAMS,CAAE,EACNE,EAAI,EAAGA,EAAIU,EAAE,OAAQV,IAC1B,GAAKU,EAAGV,CAAE,IAAMD,EACf,MAAO,GAITW,EAAE,KAAMX,CAAI,CACb,CACA,MAAO,EACR,CAOA,SAASJ,GAAQ,CAChB,IAAIK,EACJ,IAAMA,EAAI,EAAGA,EAAIX,EAAK,OAAQW,IAC7BX,EAAMW,CAAE,EAAE,OAAS,EAEpBZ,EAAS,CACV,CACD,CAKAxC,EAAO,QAAUsC,KCtYjB,IAAAyB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAU,IAmCVC,GAAiBD,GAAQ,EAK7BD,EAAO,QAAUE,KCnBjB,IAAIC,GAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,GAAU,IAKdF,GAAaC,EAAM,UAAWC,EAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isNonNegativeInteger", "format", "validate", "opts", "options", "require_pool", "__commonJSMin", "exports", "module", "pool", "out", "i", "require_bytes_per_element", "__commonJSMin", "exports", "module", "require_factory", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isCollection", "isTypedArrayLike", "isArrayBuffer", "isComplexDataType", "isComplex64Array", "isComplex128Array", "isBooleanArray", "setReadOnly", "setReadOnlyAccessor", "ctors", "reinterpret64", "reinterpret128", "reinterpretBoolean", "resolveGetter", "resolveSetter", "ARRAY_DEFAULTS", "format", "ArrayBuffer", "ceil", "floor", "ceil2", "log2", "min", "defaults", "validate", "createPool", "BYTES_PER_ELEMENT", "DEFAULT_DTYPE", "Complex64Array", "Complex128Array", "BooleanArray", "isCmplx64Array", "arr", "isCmplx128Array", "isBoolArray", "factory", "options", "nbytes", "pool", "opts", "err", "malloc", "calloc", "free", "clear", "getBytes", "arraybuffer", "n", "buf", "i", "typedarray", "ctor", "len", "dtype", "nargs", "out", "set", "get", "tmp", "p", "require_main", "__commonJSMin", "exports", "module", "factory", "typedarraypool", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a2727d6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,333 +0,0 @@ - -{{alias}}( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - Memory is **uninitialized**, which means that the contents of a returned - typed array may contain sensitive contents. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}() - [] - > arr = {{alias}}( 'float32' ) - [] - - -{{alias}}( length[, dtype] ) - Returns an uninitialized typed array having a specified length from a typed - array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > arr = {{alias}}( 5, 'int32' ) - - - -{{alias}}( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - This method shares the same security vulnerabilities mentioned above. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc() - - > arr = {{alias}}.malloc( 'float32' ) - - - -{{alias}}.malloc( length[, dtype] ) - Returns a typed array having a specified length from a typed array memory - pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc( 5 ) - - > arr = {{alias}}.malloc( 5, 'int32' ) - - - -{{alias}}.malloc( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}.malloc( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.calloc( [dtype] ) - Returns a zero-initialized typed array from a typed array memory pool. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc() - [] - > arr = {{alias}}.calloc( 'float32' ) - [] - - -{{alias}}.calloc( length[, dtype] ) - Returns a zero-initialized typed array having a specified length from a - typed array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}.calloc( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}.free( buf ) - Frees a typed array or typed array buffer for use in a future allocation. - - Parameters - ---------- - buf: TypedArray|ArrayBuffer - Typed array or typed array buffer to free. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - - -{{alias}}.clear() - Clears the typed array pool allowing garbage collection of previously - allocated (and currently free) array buffers. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - > {{alias}}.clear(); - - -{{alias}}.highWaterMark - Read-only property returning the pool's high water mark. - - Once a high water mark is reached, typed array allocation fails. - - Examples - -------- - > {{alias}}.highWaterMark - - - -{{alias}}.nbytes - Read-only property returning the total number of allocated bytes. - - The returned value is the total accumulated value. Hence, anytime a pool - must allocate a new array buffer (i.e., more memory), the pool increments - this value. - - The only time this value is decremented is when a pool is cleared. - - This behavior means that, while allocated buffers which are never freed may, - in fact, be garbage collected, they continue to count against the high water - mark limit. - - Accordingly, you should *always* free allocated buffers in order to prevent - the pool from believing that non-freed buffers are continually in use. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.nbytes - - - -{{alias}}.factory( [options] ) - Creates a typed array pool. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.highWaterMark: integer (optional) - Maximum total memory (in bytes) which can be allocated. - - Returns - ------- - fcn: Function - Function for creating typed arrays from a typed array memory pool. - - Examples - -------- - > var pool = {{alias}}.factory(); - > var arr1 = pool( 3, 'float64' ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 4336c42..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,193 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-empty */ -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import typedarraypool = require( './index' ); - - -// TESTS // - -// The function returns a typed array or null... -{ - typedarraypool(); // $ExpectType TypedArrayOrNull - typedarraypool( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the function is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool( true ); // $ExpectError - typedarraypool( false ); // $ExpectError - typedarraypool( null ); // $ExpectError - typedarraypool( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized data type... -{ - typedarraypool( 4, true ); // $ExpectError - typedarraypool( 4, false ); // $ExpectError - typedarraypool( 4, null ); // $ExpectError - typedarraypool( 4, 'abc' ); // $ExpectError - typedarraypool( 4, 123 ); // $ExpectError - typedarraypool( 4, [] ); // $ExpectError - typedarraypool( 4, {} ); // $ExpectError - typedarraypool( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an incorrect number of arguments... -{ - typedarraypool( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `malloc` method which returns a typed array or null... -{ - typedarraypool.malloc(); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.malloc( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `malloc` method is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool.malloc( true ); // $ExpectError - typedarraypool.malloc( false ); // $ExpectError - typedarraypool.malloc( null ); // $ExpectError - typedarraypool.malloc( {} ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.malloc( 4, true ); // $ExpectError - typedarraypool.malloc( 4, false ); // $ExpectError - typedarraypool.malloc( 4, null ); // $ExpectError - typedarraypool.malloc( 4, 'abc' ); // $ExpectError - typedarraypool.malloc( 4, 123 ); // $ExpectError - typedarraypool.malloc( 4, [] ); // $ExpectError - typedarraypool.malloc( 4, {} ); // $ExpectError - typedarraypool.malloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided an incorrect number of arguments... -{ - typedarraypool.malloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `calloc` method which returns a typed array or null... -{ - typedarraypool.calloc(); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `calloc` method is provided a first argument which is not a number... -{ - typedarraypool.calloc( 'abc' ); // $ExpectError - typedarraypool.calloc( true ); // $ExpectError - typedarraypool.calloc( false ); // $ExpectError - typedarraypool.calloc( null ); // $ExpectError - typedarraypool.calloc( {} ); // $ExpectError - typedarraypool.calloc( [] ); // $ExpectError - typedarraypool.calloc( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.calloc( 4, true ); // $ExpectError - typedarraypool.calloc( 4, false ); // $ExpectError - typedarraypool.calloc( 4, null ); // $ExpectError - typedarraypool.calloc( 4, 'abc' ); // $ExpectError - typedarraypool.calloc( 4, 123 ); // $ExpectError - typedarraypool.calloc( 4, [] ); // $ExpectError - typedarraypool.calloc( 4, {} ); // $ExpectError - typedarraypool.calloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided an incorrect number of arguments... -{ - typedarraypool.calloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `factory` method which returns a typed array pool.. -{ - typedarraypool.factory(); // $ExpectType Pool - typedarraypool.factory( { 'highWaterMark': 556 } ); // $ExpectType Pool -} - -// The compiler throws an error if the `factory` method is provided a `highWaterMark` option which is not a number... -{ - typedarraypool.factory( { 'highWaterMark': true } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': false } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': 'abc' } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': null } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': [] } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': {} } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an incorrect number of arguments... -{ - typedarraypool.factory( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` method which returns void... -{ - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.free( arr ); // $ExpectType void -} - -// The compiler throws an error if the `free` method is provided a first argument which is neither a typed array nor array buffer... -{ - typedarraypool.free( true ); // $ExpectError - typedarraypool.free( false ); // $ExpectError - typedarraypool.free( 123 ); // $ExpectError - typedarraypool.free( 'abc' ); // $ExpectError - typedarraypool.free( null ); // $ExpectError - typedarraypool.free( {} ); // $ExpectError - typedarraypool.free( ( x: number ): number => x ); // $ExpectError -} - -// Attached to the main export is a `clear` method which returns void... -{ - typedarraypool.clear(); // $ExpectType void -} - -// The compiler throws an error if the `clear` method is provided arguments... -{ - typedarraypool.clear( {} ); // $ExpectError - typedarraypool.clear( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `highWaterMark` property... -{ - typedarraypool.highWaterMark; // $ExpectType number -} - -// Attached to the main export is a `nbytes` property... -{ - typedarraypool.nbytes; // $ExpectType number -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 24a7846..0000000 --- a/examples/index.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 randu = require( '@stdlib/random-base-randu' ); -var typedarraypool = require( './../lib' ); - -// Create a typed array pool which can allocate at most 1GB: -var typedarray = typedarraypool.factory({ - 'highWaterMark': 1e9 -}); - -// Inspect the pool: -console.log( 'Max bytes: %d', typedarray.highWaterMark ); -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Allocate an array for storing double-precision floating-point numbers: -var arr1 = typedarray( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Fill the array... -var i; -for ( i = 0; i < arr1.length; i++ ) { - arr1[ i ] = randu(); -} - -// Inspect array contents: -console.log( arr1 ); - -// Free the array: -typedarray.free( arr1 ); - -// Allocate another array similar to the previous one: -var arr2 = typedarray( 5, 'float64' ); -// returns - -// Check that we have been returned a new typed array view: -console.log( arr2 === arr1 ); -// => false - -// Inspect array contents: -console.log( arr2 ); - -// Free the array: -typedarray.free( arr2 ); - -// Allocate an initialized array: -var arr3 = typedarray.calloc( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect array contents: -console.log( arr3 ); - -// Free the array: -typedarray.free( arr3 ); - -// Clear the pool: -typedarray.clear(); - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 4dc8736..8298bf3 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike, RealOrComplexTypedArray, BooleanArray, NumericDataType as DataType } from '@stdlib/types/array'; import ArrayBuffer = require( '@stdlib/array-buffer' ); diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..1857d00 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-booleanarray@v0.0.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.2.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.2.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.1-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-setter@v0.2.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/array-defaults@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.1-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.2.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.2.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.2.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.2.1-esm/index.mjs";import M from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.2.2-esm/index.mjs";import W from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";var H={bool:1,float64:8,float32:4,int16:2,int32:4,int8:1,uint16:2,uint32:4,uint8:1,uint8c:1,complex64:8,complex128:16},T=g.get("dtypes.default"),L=h("complex64"),P=h("complex128"),V=h("bool");function Y(e){return e instanceof L}function q(e){return e instanceof P}function z(e){return e instanceof V}function A(g){var L,P,V,A;if(V={highWaterMark:9007199254740992},arguments.length&&(A=function(e,t){return W(t)?E(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(u("01H2t","highWaterMark",e.highWaterMark)):null:new TypeError(u("01H2V",t))}(V,g),A))throw A;return P=function(e){var t,r;for(t=[],r=0;r0){for(t=y(k(e.byteLength)),t=M(P.length-1,t),r=P[t],s=0;sV.highWaterMark?null:(t=new b(e),L+=e,t)}(w(t)*H[r]))?s:new e(s,0,t)}function C(){var e,i,n,a,g,b,x,y,w;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:T,null===(n=h(i)))throw new TypeError(u("01H2Y",i));if(e<=0)return new n(0);if(r(arguments[0]))return B(n,arguments[0],i);if(s(arguments[0])){if(y=(a=arguments[0]).length,d(a)?a=j(a,0):m(a)?a=p(a,0):l(a)?a=f(a,0):o(i)&&(y/=2),null===(g=B(n,y,i)))return g;if(q(g)||Y(g)||z(g))return g.set(a),g;for(x=c(a),b=v(g),w=0;w[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '01H2Y', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( isBooleanArray( arr ) ) {\n\t\t\t\tarr = reinterpretBoolean( arr, 0 );\n\t\t\t} else if ( isComplexDataType( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) || isBoolArray( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = resolveGetter( arr );\n\t\t\tset = resolveSetter( out );\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '01H2r', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else if ( isBoolArray( out ) ) {\n\t\t\t\ttmp = reinterpretBoolean( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( '01H2s', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'highWaterMark': 1024\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '01H2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'highWaterMark' ) ) {\n\t\topts.highWaterMark = options.highWaterMark;\n\t\tif ( !isNonNegativeInteger( opts.highWaterMark ) ) {\n\t\t\treturn new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Initializes a cache for pooled typed array buffers.\n*\n* @private\n* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size\n* @returns {ArrayArray} initialized cache\n*/\nfunction pool( n ) {\n\tvar out;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < n+1; i++ ) {\n\t\tout.push( [] );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default pool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DEFAULT_DTYPE","ARRAY_DEFAULTS","get","Complex64Array","ctors","Complex128Array","BooleanArray","isCmplx64Array","arr","isCmplx128Array","isBoolArray","factory","options","nbytes","pool","opts","err","highWaterMark","arguments","length","isObject","hasOwnProp","isNonNegativeInteger","TypeError","format","validate","n","out","i","push","createPool","ceil","log2","setReadOnly","malloc","nargs","tmp","reinterpret128","reinterpret64","reinterpretBoolean","buf","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","setReadOnlyAccessor","typedarray","ctor","len","dtype","pop","ArrayBuffer","arraybuffer","ceil2","BYTES_PER_ELEMENT","set","isString","isCollection","isComplex128Array","isComplex64Array","isBooleanArray","isComplexDataType","resolveGetter","resolveSetter","typedarraypool","main"],"mappings":";;wzFAuDIA,EAAgBC,EAAeC,IAAK,kBACpCC,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cACzBE,EAAeF,EAAO,QAY1B,SAASG,EAAgBC,GACxB,OAASA,aAAeL,CACzB,CASA,SAASM,EAAiBD,GACzB,OAASA,aAAeH,CACzB,CASA,SAASK,EAAaF,GACrB,OAASA,aAAeF,CACzB,CA6BA,SAASK,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,EChGO,CACNE,cAAiB,kBDgGbC,UAAUC,SACdH,EElFF,SAAmBD,EAAMH,GACxB,OAAMQ,EAAUR,GAGXS,EAAYT,EAAS,mBACzBG,EAAKE,cAAgBL,EAAQK,eACvBK,EAAsBP,EAAKE,gBACzB,IAAIM,UAAWC,EAAQ,QAAS,gBAAiBT,EAAKE,gBAGxD,KARC,IAAIM,UAAWC,EAAQ,QAASZ,GASzC,CFuEQa,CAAUV,EAAMH,GACjBI,GACJ,MAAMA,EAaR,OAVAF,EG3GD,SAAeY,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,CHkGQG,CAAYC,EAAMC,EAAMjB,EAAKE,iBACpCJ,EAAS,EAEToB,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,UAiKrB,WACC,IAAIC,EACAR,EACAS,EACAR,EAEJO,EAAQjB,UAAUC,OAEjBQ,EADc,IAAVQ,EACED,IACe,IAAVC,EACLD,EAAQhB,UAAW,IAEnBgB,EAAQhB,UAAW,GAAKA,UAAW,IAE1C,GAAa,OAARS,EAWJ,IARCS,EADI3B,EAAiBkB,GACfU,EAAgBV,EAAK,GAChBpB,EAAgBoB,GACrBW,EAAeX,EAAK,GACfjB,EAAaiB,GAClBY,EAAoBZ,EAAK,GAEzBA,EAEDC,EAAI,EAAGA,EAAIQ,EAAIjB,OAAQS,IAC5BQ,EAAKR,GAAM,EAGb,OAAOD,CACP,IA9LDM,EAAaC,EAAQ,QA4MrB,SAAeM,GACd,IAAId,EACAe,EACAb,EACJ,GAAKc,EAAkBF,IAASA,EAAIG,OACnCH,EAAMA,EAAIG,YACJ,IAAMC,EAAeJ,GAC3B,MAAM,IAAIjB,UAAWC,EAAQ,QAASgB,IAEvC,GAAKA,EAAIK,WAAa,EAAI,CAQzB,IAPAnB,EAAIoB,EAAOd,EAAMQ,EAAIK,aAGrBnB,EAAIqB,EAAKjC,EAAKK,OAAO,EAAGO,GAGxBe,EAAI3B,EAAMY,GACJE,EAAI,EAAGA,EAAIa,EAAEtB,OAAQS,IAC1B,GAAKa,EAAGb,KAAQY,EACf,OAAO,EAITC,EAAEZ,KAAMW,EACR,CACD,OAAO,CACP,IArODP,EAAaC,EAAQ,SA4OrB,WACC,IAAIN,EACJ,IAAMA,EAAI,EAAGA,EAAId,EAAKK,OAAQS,IAC7Bd,EAAMc,GAAIT,OAAS,EAEpBN,EAAS,CACT,IAjPDoB,EAAaC,EAAQ,gBAAiBnB,EAAKE,eAC3C+B,EAAqBd,EAAQ,UAU7B,WACC,OAAOrB,CACP,IAVMqB,EAmDP,SAASe,EAAYC,EAAMC,EAAKC,GAC/B,IAAIZ,EACJ,OAAa,IAARW,EACG,IAAID,EAAM,GAGL,QADbV,EArCD,SAAsBd,GACrB,IAAIc,EACAZ,EAMJ,OAHAA,EAAII,EAAMN,IAGDZ,EAAKK,QAAUL,EAAMc,GAAIT,OAC1BL,EAAMc,GAAIyB,MAGbxC,EAAOa,EAAIX,EAAKE,cACb,MAERuB,EAAM,IAAIc,EAAa5B,GAGvBb,GAAUa,EAEHc,EACP,CAgBMe,CAAaC,EAAOL,GAAMM,EAAmBL,KAE3CZ,EAED,IAAIU,EAAMV,EAAK,EAAGW,EACzB,CAkBD,SAASjB,IACR,IAAIC,EACAiB,EACAF,EACA1C,EACAmB,EACA+B,EACAxD,EACAiD,EACAvB,EAUJ,GALCwB,GAHDjB,EAAQjB,UAAUC,SACJwC,EAAUzC,UAAWiB,EAAM,IAEhCjB,UADRiB,GAAS,GAGDnC,EAGK,QADdkD,EAAO9C,EAAOgD,IAEb,MAAM,IAAI7B,UAAWC,EAAQ,QAAS4B,IAEvC,GAAKjB,GAAS,EACb,OAAO,IAAIe,EAAM,GAGlB,GAAK5B,EAAsBJ,UAAW,IACrC,OAAO+B,EAAYC,EAAMhC,UAAW,GAAKkC,GAG1C,GAAKQ,EAAc1C,UAAW,IAAQ,CAcrC,GAZAiC,GADA3C,EAAMU,UAAW,IACPC,OACL0C,EAAmBrD,GACvBA,EAAM6B,EAAgB7B,EAAK,GAChBsD,EAAkBtD,GAC7BA,EAAM8B,EAAe9B,EAAK,GACfuD,EAAgBvD,GAC3BA,EAAM+B,EAAoB/B,EAAK,GACpBwD,EAAmBZ,KAE9BD,GAAO,GAGK,QADbxB,EAAMsB,EAAYC,EAAMC,EAAKC,IAE5B,OAAOzB,EAER,GAAKlB,EAAiBkB,IAASpB,EAAgBoB,IAASjB,EAAaiB,GAEpE,OADAA,EAAI+B,IAAKlD,GACFmB,EAKR,IAFAzB,EAAM+D,EAAezD,GACrBkD,EAAMQ,EAAevC,GACfC,EAAI,EAAGA,EAAIuB,EAAKvB,IACrB8B,EAAK/B,EAAKC,EAAG1B,EAAKM,EAAKoB,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,QAASN,UAAW,IACjD,CAoGF,CIxUG,IAACiD,EAAiBxD,ICPrBsB,EAAAmC,EAAA,UAAAzD"} \ No newline at end of file diff --git a/lib/bytes_per_element.json b/lib/bytes_per_element.json deleted file mode 100644 index 30f02fc..0000000 --- a/lib/bytes_per_element.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "bool": 1, - "float64": 8, - "float32": 4, - "int16": 2, - "int32": 4, - "int8": 1, - "uint16": 2, - "uint32": 4, - "uint8": 1, - "uint8c": 1, - "complex64": 8, - "complex128": 16 -} diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index a421711..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +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'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'highWaterMark': 9007199254740992 - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 7f297ce..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,391 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' ); -var isComplex64Array = require( '@stdlib/assert-is-complex64array' ); -var isComplex128Array = require( '@stdlib/assert-is-complex128array' ); -var isBooleanArray = require( '@stdlib/assert-is-booleanarray' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var ctors = require( '@stdlib/array-typed-ctors' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var resolveSetter = require( '@stdlib/array-base-resolve-setter' ); -var ARRAY_DEFAULTS = require( '@stdlib/array-defaults' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil = require( '@stdlib/math-base-special-ceil' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); -var log2 = require( '@stdlib/math-base-special-log2' ); -var min = require( '@stdlib/math-base-special-min' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var createPool = require( './pool.js' ); -var BYTES_PER_ELEMENT = require( './bytes_per_element.json' ); - - -// VARIABLES // - -var DEFAULT_DTYPE = ARRAY_DEFAULTS.get( 'dtypes.default' ); -var Complex64Array = ctors( 'complex64' ); -var Complex128Array = ctors( 'complex128' ); -var BooleanArray = ctors( 'bool' ); - - -// FUNCTIONS // - -/** -* Tests whether an array is a single-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a single-precision complex floating-point number array -*/ -function isCmplx64Array( arr ) { - return ( arr instanceof Complex64Array ); -} - -/** -* Tests whether an array is a double-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a double-precision complex floating-point number array -*/ -function isCmplx128Array( arr ) { - return ( arr instanceof Complex128Array ); -} - -/** -* Tests whether an array is a boolean array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a boolean array -*/ -function isBoolArray( arr ) { - return ( arr instanceof BooleanArray ); -} - - -// MAIN // - -/** -* Creates a typed array pool. -* -* @param {Options} [options] - pool options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} allocator -* -* @example -* var typedarraypool = factory(); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -function factory( options ) { - var nbytes; - var pool; - var opts; - var err; - - opts = defaults(); - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - pool = createPool( ceil( log2( opts.highWaterMark ) ) ); - nbytes = 0; - - setReadOnly( malloc, 'malloc', malloc ); // circular reference - setReadOnly( malloc, 'calloc', calloc ); - setReadOnly( malloc, 'free', free ); - setReadOnly( malloc, 'clear', clear ); - setReadOnly( malloc, 'highWaterMark', opts.highWaterMark ); - setReadOnlyAccessor( malloc, 'nbytes', getBytes ); - - return malloc; - - /** - * Returns the number of allocated bytes. - * - * @private - * @returns {NonNegativeInteger} number of allocated bytes - */ - function getBytes() { - return nbytes; - } - - /** - * Returns an array buffer. - * - * @private - * @param {NonNegativeInteger} n - number of bytes - * @returns {(ArrayBuffer|null)} array buffer or null - */ - function arraybuffer( n ) { - var buf; - var i; - - // Convert the number of bytes to an index in our pool table: - i = log2( n ); - - // If we already have an available array buffer, use it... - if ( i < pool.length && pool[ i ].length ) { - return pool[ i ].pop(); - } - // Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate... - if ( nbytes+n > opts.highWaterMark ) { - return null; - } - buf = new ArrayBuffer( n ); - - // Update the running counter of allocated bytes: - nbytes += n; - - return buf; - } - - /** - * Returns a typed array. - * - * @private - * @param {Function} ctor - typed array constructor - * @param {NonNegativeInteger} len - view length - * @param {string} dtype - data type - * @returns {(TypedArray|null)} typed array or null - */ - function typedarray( ctor, len, dtype ) { - var buf; - if ( len === 0 ) { - return new ctor( 0 ); - } - buf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] ); - if ( buf === null ) { - return buf; - } - return new ctor( buf, 0, len ); - } - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length or an array-like object - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function malloc() { - var nargs; - var dtype; - var ctor; - var arr; - var out; - var set; - var get; - var len; - var i; - - nargs = arguments.length; - if ( nargs && isString( arguments[ nargs-1 ] ) ) { - nargs -= 1; - dtype = arguments[ nargs ]; - } else { - dtype = DEFAULT_DTYPE; - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( '01H2Y', dtype ) ); - } - if ( nargs <= 0 ) { - return new ctor( 0 ); - } - // Check if provided a typed array length... - if ( isNonNegativeInteger( arguments[ 0 ] ) ) { - return typedarray( ctor, arguments[ 0 ], dtype ); - } - // Check if provided an array-like object containing data elements... - if ( isCollection( arguments[ 0 ] ) ) { - arr = arguments[ 0 ]; - len = arr.length; - if ( isComplex128Array( arr ) ) { - arr = reinterpret128( arr, 0 ); - } else if ( isComplex64Array( arr ) ) { - arr = reinterpret64( arr, 0 ); - } else if ( isBooleanArray( arr ) ) { - arr = reinterpretBoolean( arr, 0 ); - } else if ( isComplexDataType( dtype ) ) { - // Assume we've been provided an array of interleaved real and imaginary components... - len /= 2; - } - out = typedarray( ctor, len, dtype ); - if ( out === null ) { - return out; - } - if ( isCmplx128Array( out ) || isCmplx64Array( out ) || isBoolArray( out ) ) { - out.set( arr ); - return out; - } - // Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other "unsafe" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things... - get = resolveGetter( arr ); - set = resolveSetter( out ); - for ( i = 0; i < len; i++ ) { - set( out, i, get( arr, i ) ); - } - return out; - } - throw new TypeError( format( '01H2r', arguments[ 0 ] ) ); - } - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {NonNegativeInteger} [len=0] - array length - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function calloc() { - var nargs; - var out; - var tmp; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - out = malloc(); - } else if ( nargs === 1 ) { - out = malloc( arguments[ 0 ] ); - } else { - out = malloc( arguments[ 0 ], arguments[ 1 ] ); - } - if ( out !== null ) { - // Initialize the memory... - if ( isCmplx128Array( out ) ) { - tmp = reinterpret128( out, 0 ); - } else if ( isCmplx64Array( out ) ) { - tmp = reinterpret64( out, 0 ); - } else if ( isBoolArray( out ) ) { - tmp = reinterpretBoolean( out, 0 ); - } else { - tmp = out; - } - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = 0.0; - } - } - return out; - } - - /** - * Frees a typed array or typed array buffer. - * - * ## Notes - * - * - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., "freeing" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool. - * - * @private - * @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free - * @throws {TypeError} must provide a typed array or typed array buffer - * @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed - */ - function free( buf ) { - var n; - var p; - var i; - if ( isTypedArrayLike( buf ) && buf.buffer ) { - buf = buf.buffer; - } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( '01H2s', buf ) ); - } - if ( buf.byteLength > 0 ) { - n = floor( log2( buf.byteLength ) ); - - // Prohibit "freeing" array buffers which would potentially allow users to circumvent high water mark limits: - n = min( pool.length-1, n ); - - // Ensure that we do not attempt to free the same buffer more than once... - p = pool[ n ]; - for ( i = 0; i < p.length; i++ ) { - if ( p[ i ] === buf ) { - return false; - } - } - // Add the buffer to our pool of free buffers: - p.push( buf ); - } - return true; - } - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @private - */ - function clear() { - var i; - for ( i = 0; i < pool.length; i++ ) { - pool[ i ].length = 0; - } - nbytes = 0; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6c12a4e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Typed array pool. -* -* @module @stdlib/array-pool -* -* @example -* var typedarraypool = require( '@stdlib/array-pool' ); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8f69ee3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,63 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @name typedarraypool -* @type {Function} -* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a valid array length or an array-like object -* @throws {TypeError} must provide a recognized data type -* @returns {(TypedArray|null)} typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -var typedarraypool = factory(); - - -// EXPORTS // - -module.exports = typedarraypool; diff --git a/lib/pool.js b/lib/pool.js deleted file mode 100644 index 5abd287..0000000 --- a/lib/pool.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Initializes a cache for pooled typed array buffers. -* -* @private -* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size -* @returns {ArrayArray} initialized cache -*/ -function pool( n ) { - var out; - var i; - - out = []; - for ( i = 0; i < n+1; i++ ) { - out.push( [] ); - } - return out; -} - - -// EXPORTS // - -module.exports = pool; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index da746bb..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'highWaterMark': 1024 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '01H2V', options ) ); - } - if ( hasOwnProp( options, 'highWaterMark' ) ) { - opts.highWaterMark = options.highWaterMark; - if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 994a553..ce31461 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Typed array pool.", "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,83 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-is-complex-floating-point-data-type": "^0.2.1", - "@stdlib/array-base-resolve-getter": "^0.2.1", - "@stdlib/array-base-resolve-setter": "^0.2.1", - "@stdlib/array-buffer": "^0.2.1", - "@stdlib/array-defaults": "^0.2.1", - "@stdlib/array-typed-ctors": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-arraybuffer": "^0.2.1", - "@stdlib/assert-is-booleanarray": "^0.0.1", - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-complex128array": "^0.2.1", - "@stdlib/assert-is-complex64array": "^0.2.1", - "@stdlib/assert-is-nonnegative-integer": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/assert-is-string": "^0.2.1", - "@stdlib/assert-is-typed-array-like": "^0.2.1", - "@stdlib/math-base-special-ceil": "^0.2.1", - "@stdlib/math-base-special-ceil2": "^0.2.1", - "@stdlib/math-base-special-floor": "^0.2.2", - "@stdlib/math-base-special-log2": "^0.2.1", - "@stdlib/math-base-special-min": "^0.2.2", - "@stdlib/strided-base-reinterpret-boolean": "^0.0.1", - "@stdlib/strided-base-reinterpret-complex128": "^0.2.1", - "@stdlib/strided-base-reinterpret-complex64": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-bool": "^0.0.1", - "@stdlib/array-complex128": "^0.2.1", - "@stdlib/array-complex64": "^0.2.1", - "@stdlib/array-float32": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/array-int16": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/array-int8": "^0.2.1", - "@stdlib/array-uint16": "^0.2.1", - "@stdlib/array-uint32": "^0.2.1", - "@stdlib/array-uint8": "^0.2.1", - "@stdlib/array-uint8c": "^0.2.1", - "@stdlib/assert-instance-of": "^0.2.1", - "@stdlib/assert-is-complex-typed-array": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-typed-array": "^0.2.1", - "@stdlib/boolean-ctor": "^0.2.1", - "@stdlib/complex-float32-ctor": "^0.0.1", - "@stdlib/complex-float64-ctor": "^0.0.1", - "@stdlib/complex-imag": "^0.2.1", - "@stdlib/complex-imagf": "^0.2.1", - "@stdlib/complex-real": "^0.2.1", - "@stdlib/complex-realf": "^0.2.1", - "@stdlib/math-base-special-pow": "^0.2.1", - "@stdlib/random-base-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9bac0b8 --- /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.factory.js b/test/test.factory.js deleted file mode 100644 index 7344c01..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,2401 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function (no options)', function test( t ) { - t.strictEqual( typeof factory(), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - t.strictEqual( typeof factory( {} ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided a `highWaterMark` option which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (length)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a function which returns a typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=bool)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, length)', function test( t ) { - var typedarraypool = factory(); - var arr; - - arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=bool, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=bool, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ true, false, false, true ]; - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( v, arr[ 0 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( v, arr[ 1 ], 'returns expected value' ); - - v = out.get( 2 ); - t.strictEqual( v, arr[ 2 ], 'returns expected value' ); - - v = out.get( 3 ); - t.strictEqual( v, arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=bool, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Uint8Array( 0 ); - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8Array( [ 1, 0, 0, 1 ] ); - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( v, true, 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( v, false, 'returns expected value' ); - - v = out.get( 2 ); - t.strictEqual( v, false, 'returns expected value' ); - - v = out.get( 3 ); - t.strictEqual( v, true, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a `malloc` method which is a circular reference', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=bool)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=bool, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'bool' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( Boolean( i%2 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( v, false, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - var buf; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the returned function is a property which returns the pool\'s high water mark', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function supports specifying a high water mark which limits the total amount of memory a pool can allocate', function test( t ) { - var typedarraypool; - var arr1; - var arr2; - - typedarraypool = factory({ - 'highWaterMark': 64 // bytes - }); - - typedarraypool.clear(); - - arr1 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr1.length, 8, 'returns expected value' ); - t.strictEqual( arr1.byteLength, 64, 'returns expected value' ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - typedarraypool.free( arr1 ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Create an array which is less than or equal to the high water mark: - arr2 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr2.length, 8, 'returns expected value' ); - t.strictEqual( arr2.byteLength, 64, 'returns expected value' ); - - typedarraypool.free( arr2 ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a property which returns the total number of accumulated bytes', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var typedarraypool; - var arrs; - var i; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index e60c54f..0000000 --- a/test/test.js +++ /dev/null @@ -1,1935 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var real = require( '@stdlib/complex-real' ); -var realf = require( '@stdlib/complex-realf' ); -var imag = require( '@stdlib/complex-imag' ); -var imagf = require( '@stdlib/complex-imagf' ); -var typedarraypool = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=bool)', function test( t ) { - var arr = typedarraypool( 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=bool, length)', function test( t ) { - var arr = typedarraypool( 10, 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=bool, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ true, false, false, true ]; - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( v, arr[ 0 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( v, arr[ 1 ], 'returns expected value' ); - - v = out.get( 2 ); - t.strictEqual( v, arr[ 2 ], 'returns expected value' ); - - v = out.get( 3 ); - t.strictEqual( v, arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=bool, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Uint8Array( 0 ); - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8Array( [ 1, 0, 0, 1 ] ); - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( v, true, 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( v, false, 'returns expected value' ); - - v = out.get( 2 ); - t.strictEqual( v, false, 'returns expected value' ); - - v = out.get( 3 ); - t.strictEqual( v, true, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=bool)', function test( t ) { - var arr = typedarraypool.calloc( 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=bool, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'bool' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( Boolean( i%2 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( v, false, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -}); From 2edc8bc0cf63bbd6b2456bb3c44fe6c1a5822415 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 17 Jul 2024 10:18:58 +0000 Subject: [PATCH 095/103] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index ce4ba27..7f297ce 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -38,7 +38,7 @@ var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); var resolveSetter = require( '@stdlib/array-base-resolve-setter' ); var ARRAY_DEFAULTS = require( '@stdlib/array-defaults' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ArrayBuffer = require( '@stdlib/array-buffer' ); var ceil = require( '@stdlib/math-base-special-ceil' ); var floor = require( '@stdlib/math-base-special-floor' ); @@ -243,7 +243,7 @@ function factory( options ) { } ctor = ctors( dtype ); if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '01H2Y', dtype ) ); } if ( nargs <= 0 ) { return new ctor( 0 ); @@ -282,7 +282,7 @@ function factory( options ) { } return out; } - throw new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) ); + throw new TypeError( format( '01H2r', arguments[ 0 ] ) ); } /** @@ -350,7 +350,7 @@ function factory( options ) { if ( isTypedArrayLike( buf ) && buf.buffer ) { buf = buf.buffer; } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) ); + throw new TypeError( format( '01H2s', buf ) ); } if ( buf.byteLength > 0 ) { n = floor( log2( buf.byteLength ) ); diff --git a/lib/validate.js b/lib/validate.js index ce54890..da746bb 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '01H2V', options ) ); } if ( hasOwnProp( options, 'highWaterMark' ) ) { opts.highWaterMark = options.highWaterMark; if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) ); + return new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) ); } } return null; diff --git a/package.json b/package.json index 1c15779..748ec44 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "@stdlib/strided-base-reinterpret-boolean": "^0.0.1", "@stdlib/strided-base-reinterpret-complex128": "^0.2.1", "@stdlib/strided-base-reinterpret-complex64": "^0.2.0", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", From f743929730416abbf12b71deaf2019d4bfd65e39 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 17 Jul 2024 10:24:26 +0000 Subject: [PATCH 096/103] Remove files --- index.d.ts | 359 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5206 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 8298bf3..0000000 --- a/index.d.ts +++ /dev/null @@ -1,359 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike, RealOrComplexTypedArray, BooleanArray, NumericDataType as DataType } from '@stdlib/types/array'; -import ArrayBuffer = require( '@stdlib/array-buffer' ); - -/** -* Typed array or null. -*/ -type TypedArrayOrNull = RealOrComplexTypedArray | BooleanArray | null; - -/** -* Interface defining pool options. -*/ -interface Options { - /** - * Maximum total memory which can be allocated. - */ - highWaterMark?: number; -} - -/** -* Pool interface. -*/ -interface Pool { - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr = typedarraypool(); - * // returns [] - * - * @example - * var arr = typedarraypool( 'float32' ); - * // returns [] - */ - ( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * // Allocate an array of doubles: - * var arr = typedarraypool( 5, 'float64' ); - * // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * typedarraypool.free( arr ); - * - * @example - * var arr1 = typedarraypool( [ 0.5, 0.5, 0.5 ] ); - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * @example - * var arr1 = [ 0.5, 0.5, 0.5 ]; - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - */ - ( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc(); - * // returns [] - * - * var arr2 = typedarraypool.calloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param length - typed array length - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc( 5 ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * var arr2 = typedarraypool.calloc( 5, 'uint8' ); - * // returns [ 0, 0, 0, 0, 0 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( length: number, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc(); - * // returns [] - * - * var arr2 = typedarraypool.malloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc( 5 ); - * // returns - * - * var arr2 = typedarraypool.malloc( 5, 'uint8' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 5.0, -3.0, 2.0 ] ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr2 = typedarraypool.malloc( arr1 ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr3 = typedarraypool.malloc( arr1, 'int32' ); - * // returns [ 5, -3, 2 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * typedarraypool.free( arr3 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ] ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * var arr2 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ], 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Frees a typed array or typed array buffer for use in a future allocation. - * - * @param buf - typed array or typed array buffer to free - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array for use in a future allocation: - * typedarraypool.free( arr ); - * - * // Create another typed array: - * arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array buffer for use in a future allocation: - * typedarraypool.free( arr.buffer ); - */ - free( buf: RealOrComplexTypedArray | BooleanArray | ArrayBuffer ): void; - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr ); - * - * // ... - * - * // Clear all freed buffers: - * typedarraypool.clear(); - */ - clear(): void; - - /** - * Read-only property returning the pool's high water mark. - * - * ## Notes - * - * - Once a high water mark is reached, typed array allocation fails. - * - * @example - * var limit = typedarraypool.highWaterMark; - * // returns - */ - readonly highWaterMark: number; - - /** - * Read-only property returning the total number of allocated bytes. - * - * @example - * var arr = typedarraypool( 5, 'float64' ); - * - * var nbytes = typedarraypool.nbytes; - * // returns - */ - readonly nbytes: number; - - /** - * Creates a typed array pool. - * - * @param options - pool options - * @param options.highWaterMark - maximum total memory which can be allocated - * @throws must provide valid options - * @returns allocator - * - * @example - * var allocator = typedarraypool.factory(); - * - * // Allocate an array of doubles: - * var arr = allocator( 5, 'float64' ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * allocator.free( arr ); - */ - factory( options?: Options ): Pool; -} - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @param arg - an array length or an array-like object -* @param dtype - data type (default: 'float64') -* @returns typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -declare var typedarraypool: Pool; - - -// EXPORTS // - -export = typedarraypool; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 1857d00..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-booleanarray@v0.0.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.2.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.2.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.1-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-setter@v0.2.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/array-defaults@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.1-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.2.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.2.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.2.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.2.1-esm/index.mjs";import M from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.2.2-esm/index.mjs";import W from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";var H={bool:1,float64:8,float32:4,int16:2,int32:4,int8:1,uint16:2,uint32:4,uint8:1,uint8c:1,complex64:8,complex128:16},T=g.get("dtypes.default"),L=h("complex64"),P=h("complex128"),V=h("bool");function Y(e){return e instanceof L}function q(e){return e instanceof P}function z(e){return e instanceof V}function A(g){var L,P,V,A;if(V={highWaterMark:9007199254740992},arguments.length&&(A=function(e,t){return W(t)?E(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(u("01H2t","highWaterMark",e.highWaterMark)):null:new TypeError(u("01H2V",t))}(V,g),A))throw A;return P=function(e){var t,r;for(t=[],r=0;r0){for(t=y(k(e.byteLength)),t=M(P.length-1,t),r=P[t],s=0;sV.highWaterMark?null:(t=new b(e),L+=e,t)}(w(t)*H[r]))?s:new e(s,0,t)}function C(){var e,i,n,a,g,b,x,y,w;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:T,null===(n=h(i)))throw new TypeError(u("01H2Y",i));if(e<=0)return new n(0);if(r(arguments[0]))return B(n,arguments[0],i);if(s(arguments[0])){if(y=(a=arguments[0]).length,d(a)?a=j(a,0):m(a)?a=p(a,0):l(a)?a=f(a,0):o(i)&&(y/=2),null===(g=B(n,y,i)))return g;if(q(g)||Y(g)||z(g))return g.set(a),g;for(x=c(a),b=v(g),w=0;w[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '01H2Y', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( isBooleanArray( arr ) ) {\n\t\t\t\tarr = reinterpretBoolean( arr, 0 );\n\t\t\t} else if ( isComplexDataType( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) || isBoolArray( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = resolveGetter( arr );\n\t\t\tset = resolveSetter( out );\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '01H2r', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else if ( isBoolArray( out ) ) {\n\t\t\t\ttmp = reinterpretBoolean( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( '01H2s', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'highWaterMark': 1024\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '01H2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'highWaterMark' ) ) {\n\t\topts.highWaterMark = options.highWaterMark;\n\t\tif ( !isNonNegativeInteger( opts.highWaterMark ) ) {\n\t\t\treturn new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Initializes a cache for pooled typed array buffers.\n*\n* @private\n* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size\n* @returns {ArrayArray} initialized cache\n*/\nfunction pool( n ) {\n\tvar out;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < n+1; i++ ) {\n\t\tout.push( [] );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default pool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DEFAULT_DTYPE","ARRAY_DEFAULTS","get","Complex64Array","ctors","Complex128Array","BooleanArray","isCmplx64Array","arr","isCmplx128Array","isBoolArray","factory","options","nbytes","pool","opts","err","highWaterMark","arguments","length","isObject","hasOwnProp","isNonNegativeInteger","TypeError","format","validate","n","out","i","push","createPool","ceil","log2","setReadOnly","malloc","nargs","tmp","reinterpret128","reinterpret64","reinterpretBoolean","buf","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","setReadOnlyAccessor","typedarray","ctor","len","dtype","pop","ArrayBuffer","arraybuffer","ceil2","BYTES_PER_ELEMENT","set","isString","isCollection","isComplex128Array","isComplex64Array","isBooleanArray","isComplexDataType","resolveGetter","resolveSetter","typedarraypool","main"],"mappings":";;wzFAuDIA,EAAgBC,EAAeC,IAAK,kBACpCC,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cACzBE,EAAeF,EAAO,QAY1B,SAASG,EAAgBC,GACxB,OAASA,aAAeL,CACzB,CASA,SAASM,EAAiBD,GACzB,OAASA,aAAeH,CACzB,CASA,SAASK,EAAaF,GACrB,OAASA,aAAeF,CACzB,CA6BA,SAASK,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,EChGO,CACNE,cAAiB,kBDgGbC,UAAUC,SACdH,EElFF,SAAmBD,EAAMH,GACxB,OAAMQ,EAAUR,GAGXS,EAAYT,EAAS,mBACzBG,EAAKE,cAAgBL,EAAQK,eACvBK,EAAsBP,EAAKE,gBACzB,IAAIM,UAAWC,EAAQ,QAAS,gBAAiBT,EAAKE,gBAGxD,KARC,IAAIM,UAAWC,EAAQ,QAASZ,GASzC,CFuEQa,CAAUV,EAAMH,GACjBI,GACJ,MAAMA,EAaR,OAVAF,EG3GD,SAAeY,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,CHkGQG,CAAYC,EAAMC,EAAMjB,EAAKE,iBACpCJ,EAAS,EAEToB,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,UAiKrB,WACC,IAAIC,EACAR,EACAS,EACAR,EAEJO,EAAQjB,UAAUC,OAEjBQ,EADc,IAAVQ,EACED,IACe,IAAVC,EACLD,EAAQhB,UAAW,IAEnBgB,EAAQhB,UAAW,GAAKA,UAAW,IAE1C,GAAa,OAARS,EAWJ,IARCS,EADI3B,EAAiBkB,GACfU,EAAgBV,EAAK,GAChBpB,EAAgBoB,GACrBW,EAAeX,EAAK,GACfjB,EAAaiB,GAClBY,EAAoBZ,EAAK,GAEzBA,EAEDC,EAAI,EAAGA,EAAIQ,EAAIjB,OAAQS,IAC5BQ,EAAKR,GAAM,EAGb,OAAOD,CACP,IA9LDM,EAAaC,EAAQ,QA4MrB,SAAeM,GACd,IAAId,EACAe,EACAb,EACJ,GAAKc,EAAkBF,IAASA,EAAIG,OACnCH,EAAMA,EAAIG,YACJ,IAAMC,EAAeJ,GAC3B,MAAM,IAAIjB,UAAWC,EAAQ,QAASgB,IAEvC,GAAKA,EAAIK,WAAa,EAAI,CAQzB,IAPAnB,EAAIoB,EAAOd,EAAMQ,EAAIK,aAGrBnB,EAAIqB,EAAKjC,EAAKK,OAAO,EAAGO,GAGxBe,EAAI3B,EAAMY,GACJE,EAAI,EAAGA,EAAIa,EAAEtB,OAAQS,IAC1B,GAAKa,EAAGb,KAAQY,EACf,OAAO,EAITC,EAAEZ,KAAMW,EACR,CACD,OAAO,CACP,IArODP,EAAaC,EAAQ,SA4OrB,WACC,IAAIN,EACJ,IAAMA,EAAI,EAAGA,EAAId,EAAKK,OAAQS,IAC7Bd,EAAMc,GAAIT,OAAS,EAEpBN,EAAS,CACT,IAjPDoB,EAAaC,EAAQ,gBAAiBnB,EAAKE,eAC3C+B,EAAqBd,EAAQ,UAU7B,WACC,OAAOrB,CACP,IAVMqB,EAmDP,SAASe,EAAYC,EAAMC,EAAKC,GAC/B,IAAIZ,EACJ,OAAa,IAARW,EACG,IAAID,EAAM,GAGL,QADbV,EArCD,SAAsBd,GACrB,IAAIc,EACAZ,EAMJ,OAHAA,EAAII,EAAMN,IAGDZ,EAAKK,QAAUL,EAAMc,GAAIT,OAC1BL,EAAMc,GAAIyB,MAGbxC,EAAOa,EAAIX,EAAKE,cACb,MAERuB,EAAM,IAAIc,EAAa5B,GAGvBb,GAAUa,EAEHc,EACP,CAgBMe,CAAaC,EAAOL,GAAMM,EAAmBL,KAE3CZ,EAED,IAAIU,EAAMV,EAAK,EAAGW,EACzB,CAkBD,SAASjB,IACR,IAAIC,EACAiB,EACAF,EACA1C,EACAmB,EACA+B,EACAxD,EACAiD,EACAvB,EAUJ,GALCwB,GAHDjB,EAAQjB,UAAUC,SACJwC,EAAUzC,UAAWiB,EAAM,IAEhCjB,UADRiB,GAAS,GAGDnC,EAGK,QADdkD,EAAO9C,EAAOgD,IAEb,MAAM,IAAI7B,UAAWC,EAAQ,QAAS4B,IAEvC,GAAKjB,GAAS,EACb,OAAO,IAAIe,EAAM,GAGlB,GAAK5B,EAAsBJ,UAAW,IACrC,OAAO+B,EAAYC,EAAMhC,UAAW,GAAKkC,GAG1C,GAAKQ,EAAc1C,UAAW,IAAQ,CAcrC,GAZAiC,GADA3C,EAAMU,UAAW,IACPC,OACL0C,EAAmBrD,GACvBA,EAAM6B,EAAgB7B,EAAK,GAChBsD,EAAkBtD,GAC7BA,EAAM8B,EAAe9B,EAAK,GACfuD,EAAgBvD,GAC3BA,EAAM+B,EAAoB/B,EAAK,GACpBwD,EAAmBZ,KAE9BD,GAAO,GAGK,QADbxB,EAAMsB,EAAYC,EAAMC,EAAKC,IAE5B,OAAOzB,EAER,GAAKlB,EAAiBkB,IAASpB,EAAgBoB,IAASjB,EAAaiB,GAEpE,OADAA,EAAI+B,IAAKlD,GACFmB,EAKR,IAFAzB,EAAM+D,EAAezD,GACrBkD,EAAMQ,EAAevC,GACfC,EAAI,EAAGA,EAAIuB,EAAKvB,IACrB8B,EAAK/B,EAAKC,EAAG1B,EAAKM,EAAKoB,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,QAASN,UAAW,IACjD,CAoGF,CIxUG,IAACiD,EAAiBxD,ICPrBsB,EAAAmC,EAAA,UAAAzD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9bac0b8..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 76155a428b9a1b78afa0b4309fb1b9a607a81aaa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 17 Jul 2024 10:24:51 +0000 Subject: [PATCH 097/103] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 139 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.calloc.js | 265 -- benchmark/benchmark.factory.js | 71 - benchmark/benchmark.js | 265 -- benchmark/benchmark.length.bool.js | 102 - benchmark/benchmark.length.complex128.js | 102 - benchmark/benchmark.length.complex64.js | 102 - benchmark/benchmark.length.float32.js | 102 - benchmark/benchmark.length.float64.js | 102 - benchmark/benchmark.length.int16.js | 102 - benchmark/benchmark.length.int32.js | 102 - benchmark/benchmark.length.int8.js | 102 - benchmark/benchmark.length.uint16.js | 102 - benchmark/benchmark.length.uint32.js | 102 - benchmark/benchmark.length.uint8.js | 102 - benchmark/benchmark.length.uint8c.js | 102 - benchmark/benchmark.malloc.js | 265 -- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 53 - dist/index.js.map | 7 - docs/repl.txt | 333 -- docs/types/test.ts | 193 - examples/index.js | 80 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/bytes_per_element.json | 14 - lib/defaults.js | 42 - lib/factory.js | 391 -- lib/index.js | 56 - lib/main.js | 63 - lib/pool.js | 44 - lib/validate.js | 66 - package.json | 104 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 2401 ---------- test/test.js | 1935 -------- 63 files changed, 4872 insertions(+), 11305 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.calloc.js delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.bool.js delete mode 100644 benchmark/benchmark.length.complex128.js delete mode 100644 benchmark/benchmark.length.complex64.js delete mode 100644 benchmark/benchmark.length.float32.js delete mode 100644 benchmark/benchmark.length.float64.js delete mode 100644 benchmark/benchmark.length.int16.js delete mode 100644 benchmark/benchmark.length.int32.js delete mode 100644 benchmark/benchmark.length.int8.js delete mode 100644 benchmark/benchmark.length.uint16.js delete mode 100644 benchmark/benchmark.length.uint32.js delete mode 100644 benchmark/benchmark.length.uint8.js delete mode 100644 benchmark/benchmark.length.uint8c.js delete mode 100644 benchmark/benchmark.malloc.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/bytes_per_element.json delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/pool.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ea35f20..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/array/pool) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6f7c875..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/array/pool) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 869c4e9..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f92a6c5..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -481,7 +478,7 @@ console.log( 'nbytes: %d', typedarray.nbytes ); ## 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]. @@ -548,11 +545,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-arraybuffer]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer -[@stdlib/array/typed-dtypes]: https://github.com/stdlib-js/array-typed-dtypes +[@stdlib/array/typed-dtypes]: https://github.com/stdlib-js/array-typed-dtypes/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/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.calloc.js b/benchmark/benchmark.calloc.js deleted file mode 100644 index 2a04c65..0000000 --- a/benchmark/benchmark.calloc.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var isBooleanArray = require( '@stdlib/assert-is-booleanarray' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':calloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=bool', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'bool' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isBooleanArray( arr ) ) { - b.fail( 'should return a boolean array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 58918bb..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = typedarray.factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:highWaterMark', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'highWaterMark': 0 - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.highWaterMark = i; - f = typedarray.factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 46c6397..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var isBooleanArray = require( '@stdlib/assert-is-booleanarray' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=bool', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'bool' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isBooleanArray( arr ) ) { - b.fail( 'should return a boolean array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.bool.js b/benchmark/benchmark.length.bool.js deleted file mode 100644 index d9ad47b..0000000 --- a/benchmark/benchmark.length.bool.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isBooleanArray = require( '@stdlib/assert-is-booleanarray' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'bool' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isBooleanArray( arr ) ) { - b.fail( 'should return a boolean array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=bool,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=bool,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=bool,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex128.js b/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 12c6668..0000000 --- a/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex64.js b/benchmark/benchmark.length.complex64.js deleted file mode 100644 index ca2b45c..0000000 --- a/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float32.js b/benchmark/benchmark.length.float32.js deleted file mode 100644 index b3b4508..0000000 --- a/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float64.js b/benchmark/benchmark.length.float64.js deleted file mode 100644 index 5f0132d..0000000 --- a/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int16.js b/benchmark/benchmark.length.int16.js deleted file mode 100644 index 9f253cb..0000000 --- a/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int32.js b/benchmark/benchmark.length.int32.js deleted file mode 100644 index f83e795..0000000 --- a/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int8.js b/benchmark/benchmark.length.int8.js deleted file mode 100644 index 5b01174..0000000 --- a/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint16.js b/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 32b0a5d..0000000 --- a/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint32.js b/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 290b90c..0000000 --- a/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8.js b/benchmark/benchmark.length.uint8.js deleted file mode 100644 index ff7d733..0000000 --- a/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8c.js b/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index 8f0d10a..0000000 --- a/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.malloc.js b/benchmark/benchmark.malloc.js deleted file mode 100644 index c85d2fb..0000000 --- a/benchmark/benchmark.malloc.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var isBooleanArray = require( '@stdlib/assert-is-booleanarray' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':malloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=bool', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'bool' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isBooleanArray( arr ) ) { - b.fail( 'should return a boolean array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 612de17..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/array/pool" -%% click B href "https://github.com/stdlib-js/array-pool/tree/main" -%% click C href "https://github.com/stdlib-js/array-pool/tree/production" -%% click D href "https://github.com/stdlib-js/array-pool/tree/esm" -%% click E href "https://github.com/stdlib-js/array-pool/tree/deno" -%% click F href "https://github.com/stdlib-js/array-pool/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/pool -[production-url]: https://github.com/stdlib-js/array-pool/tree/production -[deno-url]: https://github.com/stdlib-js/array-pool/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-pool/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-pool/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-pool/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-pool/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-pool/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 5160b6f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import typedarraypool from '../docs/types/index'; -export = typedarraypool; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 925147b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,53 +0,0 @@ -"use strict";var s=function(n,i){return function(){return i||n((i={exports:{}}).exports,i),i.exports}};var M=s(function(Cr,w){"use strict";function z(){return{highWaterMark:9007199254740992}}w.exports=z});var T=s(function(Or,E){"use strict";var G=require("@stdlib/assert-is-plain-object"),H=require("@stdlib/assert-has-own-property"),J=require("@stdlib/assert-is-nonnegative-integer").isPrimitive,k=require("@stdlib/string-format");function K(n,i){return G(i)?H(i,"highWaterMark")&&(n.highWaterMark=i.highWaterMark,!J(n.highWaterMark))?new TypeError(k("invalid option. `%s` option must be a nonnegative integer. Option: `%s`.","highWaterMark",n.highWaterMark)):null:new TypeError(k("invalid argument. Options argument must be an object. Value: `%s`.",i))}E.exports=K});var B=s(function(Pr,W){"use strict";function Q(n){var i,u;for(i=[],u=0;uv.highWaterMark?null:(e=new fr(r),i+=r,e)}function d(r,e,t){var a;return e===0?new r(0):(a=F(pr(e)*dr[t]),a===null?a:new r(a,0,e))}function o(){var r,e,t,a,l,A,x,c,f;if(r=arguments.length,r&&Z(arguments[r-1])?(r-=1,e=arguments[r]):e=Ar,t=p(e),t===null)throw new TypeError(y("invalid argument. Must provide a recognized data type. Value: `%s`.",e));if(r<=0)return new t(0);if($(arguments[0]))return d(t,arguments[0],e);if(rr(arguments[0])){if(a=arguments[0],c=a.length,nr(a)?a=O(a,0):ir(a)?a=C(a,0):ur(a)?a=P(a,0):tr(e)&&(c/=2),l=d(t,c,e),l===null)return l;if(R(l)||L(l)||N(l))return l.set(a),l;for(x=lr(a),A=sr(l),f=0;f0){for(e=cr(m(r.byteLength)),e=hr(u.length-1,e),t=u[e],a=0;a[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( isBooleanArray( arr ) ) {\n\t\t\t\tarr = reinterpretBoolean( arr, 0 );\n\t\t\t} else if ( isComplexDataType( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) || isBoolArray( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = resolveGetter( arr );\n\t\t\tset = resolveSetter( out );\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else if ( isBoolArray( out ) ) {\n\t\t\t\ttmp = reinterpretBoolean( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nmodule.exports = typedarraypool;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* var typedarraypool = require( '@stdlib/array-pool' );\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,cAAiB,gBAClB,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,eAAgB,IACzCD,EAAK,cAAgBC,EAAQ,cACxB,CAACJ,EAAsBG,EAAK,aAAc,GACvC,IAAI,UAAWF,EAAQ,2EAA4E,gBAAiBE,EAAK,aAAc,CAAE,EAG3I,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cA6BA,SAASC,EAAM,EAAI,CAClB,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAI,EAAE,EAAGA,IACrBD,EAAI,KAAM,CAAC,CAAE,EAEd,OAAOA,CACR,CAKAF,EAAO,QAAUC,IC3CjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,KAAQ,EACR,QAAW,EACX,QAAW,EACX,MAAS,EACT,MAAS,EACT,KAAQ,EACR,OAAU,EACV,OAAU,EACV,MAAS,EACT,OAAU,EACT,UAAa,EACb,WAAc,EAChB,ICbA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,GAAe,QAAS,8BAA+B,EACvDC,GAAmB,QAAS,oCAAqC,EACjEC,GAAgB,QAAS,+BAAgC,EACzDC,GAAoB,QAAS,+DAAgE,EAC7FC,GAAmB,QAAS,kCAAmC,EAC/DC,GAAoB,QAAS,mCAAoC,EACjEC,GAAiB,QAAS,gCAAiC,EAC3DC,EAAc,QAAS,uDAAwD,EAC/EC,GAAsB,QAAS,uDAAwD,EACvFC,EAAQ,QAAS,2BAA4B,EAC7CC,EAAgB,QAAS,4CAA6C,EACtEC,EAAiB,QAAS,6CAA8C,EACxEC,EAAqB,QAAS,0CAA2C,EACzEC,GAAgB,QAAS,mCAAoC,EAC7DC,GAAgB,QAAS,mCAAoC,EAC7DC,GAAiB,QAAS,wBAAyB,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,GAAc,QAAS,sBAAuB,EAC9CC,GAAO,QAAS,gCAAiC,EACjDC,GAAQ,QAAS,iCAAkC,EACnDC,GAAQ,QAAS,iCAAkC,EACnDC,EAAO,QAAS,gCAAiC,EACjDC,GAAM,QAAS,+BAAgC,EAC/CC,GAAW,IACXC,GAAW,IACXC,GAAa,IACbC,GAAoB,IAKpBC,GAAgBZ,GAAe,IAAK,gBAAiB,EACrDa,GAAiBnB,EAAO,WAAY,EACpCoB,GAAkBpB,EAAO,YAAa,EACtCqB,GAAerB,EAAO,MAAO,EAYjC,SAASsB,EAAgBC,EAAM,CAC9B,OAASA,aAAeJ,EACzB,CASA,SAASK,EAAiBD,EAAM,CAC/B,OAASA,aAAeH,EACzB,CASA,SAASK,EAAaF,EAAM,CAC3B,OAASA,aAAeF,EACzB,CA6BA,SAASK,GAASC,EAAU,CAC3B,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,EAAOhB,GAAS,EACX,UAAU,SACdiB,EAAMhB,GAAUe,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAAF,EAAOb,GAAYP,GAAMG,EAAMkB,EAAK,aAAc,CAAE,CAAE,EACtDF,EAAS,EAET9B,EAAakC,EAAQ,SAAUA,CAAO,EACtClC,EAAakC,EAAQ,SAAUC,CAAO,EACtCnC,EAAakC,EAAQ,OAAQE,CAAK,EAClCpC,EAAakC,EAAQ,QAASG,CAAM,EACpCrC,EAAakC,EAAQ,gBAAiBF,EAAK,aAAc,EACzD/B,GAAqBiC,EAAQ,SAAUI,CAAS,EAEzCJ,EAQP,SAASI,GAAW,CACnB,OAAOR,CACR,CASA,SAASS,EAAaC,EAAI,CACzB,IAAIC,EACAC,EAMJ,OAHAA,EAAI5B,EAAM0B,CAAE,EAGPE,EAAIX,EAAK,QAAUA,EAAMW,CAAE,EAAE,OAC1BX,EAAMW,CAAE,EAAE,IAAI,EAGjBZ,EAAOU,EAAIR,EAAK,cACb,MAERS,EAAM,IAAI/B,GAAa8B,CAAE,EAGzBV,GAAUU,EAEHC,EACR,CAWA,SAASE,EAAYC,EAAMC,EAAKC,EAAQ,CACvC,IAAIL,EACJ,OAAKI,IAAQ,EACL,IAAID,EAAM,CAAE,GAEpBH,EAAMF,EAAa1B,GAAOgC,CAAI,EAAE1B,GAAmB2B,CAAM,CAAE,EACtDL,IAAQ,KACLA,EAED,IAAIG,EAAMH,EAAK,EAAGI,CAAI,EAC9B,CAkBA,SAASX,GAAS,CACjB,IAAIa,EACAD,EACAF,EACAnB,EACAuB,EACAC,EACAC,EACAL,EACAH,EAUJ,GARAK,EAAQ,UAAU,OACbA,GAASxD,EAAU,UAAWwD,EAAM,CAAE,CAAE,GAC5CA,GAAS,EACTD,EAAQ,UAAWC,CAAM,GAEzBD,EAAQ1B,GAETwB,EAAO1C,EAAO4C,CAAM,EACfF,IAAS,KACb,MAAM,IAAI,UAAWnC,EAAQ,sEAAuEqC,CAAM,CAAE,EAE7G,GAAKC,GAAS,EACb,OAAO,IAAIH,EAAM,CAAE,EAGpB,GAAKpD,EAAsB,UAAW,CAAE,CAAE,EACzC,OAAOmD,EAAYC,EAAM,UAAW,CAAE,EAAGE,CAAM,EAGhD,GAAKrD,GAAc,UAAW,CAAE,CAAE,EAAI,CAcrC,GAbAgC,EAAM,UAAW,CAAE,EACnBoB,EAAMpB,EAAI,OACL3B,GAAmB2B,CAAI,EAC3BA,EAAMrB,EAAgBqB,EAAK,CAAE,EAClB5B,GAAkB4B,CAAI,EACjCA,EAAMtB,EAAesB,EAAK,CAAE,EACjB1B,GAAgB0B,CAAI,EAC/BA,EAAMpB,EAAoBoB,EAAK,CAAE,EACtB7B,GAAmBkD,CAAM,IAEpCD,GAAO,GAERG,EAAML,EAAYC,EAAMC,EAAKC,CAAM,EAC9BE,IAAQ,KACZ,OAAOA,EAER,GAAKtB,EAAiBsB,CAAI,GAAKxB,EAAgBwB,CAAI,GAAKrB,EAAaqB,CAAI,EACxE,OAAAA,EAAI,IAAKvB,CAAI,EACNuB,EAKR,IAFAE,EAAM5C,GAAemB,CAAI,EACzBwB,EAAM1C,GAAeyC,CAAI,EACnBN,EAAI,EAAGA,EAAIG,EAAKH,IACrBO,EAAKD,EAAKN,EAAGQ,EAAKzB,EAAKiB,CAAE,CAAE,EAE5B,OAAOM,CACR,CACA,MAAM,IAAI,UAAWvC,EAAQ,wGAAyG,UAAW,CAAE,CAAE,CAAE,CACxJ,CAgBA,SAAS0B,GAAS,CACjB,IAAIY,EACAC,EACAG,EACAT,EAUJ,GARAK,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAMd,EAAO,EACFa,IAAU,EACrBC,EAAMd,EAAQ,UAAW,CAAE,CAAE,EAE7Bc,EAAMd,EAAQ,UAAW,CAAE,EAAG,UAAW,CAAE,CAAE,EAEzCc,IAAQ,KAWZ,IATKtB,EAAiBsB,CAAI,EACzBG,EAAM/C,EAAgB4C,EAAK,CAAE,EAClBxB,EAAgBwB,CAAI,EAC/BG,EAAMhD,EAAe6C,EAAK,CAAE,EACjBrB,EAAaqB,CAAI,EAC5BG,EAAM9C,EAAoB2C,EAAK,CAAE,EAEjCG,EAAMH,EAEDN,EAAI,EAAGA,EAAIS,EAAI,OAAQT,IAC5BS,EAAKT,CAAE,EAAI,EAGb,OAAOM,CACR,CAcA,SAASZ,EAAMK,EAAM,CACpB,IAAID,EACAY,EACAV,EACJ,GAAKhD,GAAkB+C,CAAI,GAAKA,EAAI,OACnCA,EAAMA,EAAI,eACC,CAAC9C,GAAe8C,CAAI,EAC/B,MAAM,IAAI,UAAWhC,EAAQ,4EAA6EgC,CAAI,CAAE,EAEjH,GAAKA,EAAI,WAAa,EAAI,CAQzB,IAPAD,EAAI5B,GAAOE,EAAM2B,EAAI,UAAW,CAAE,EAGlCD,EAAIzB,GAAKgB,EAAK,OAAO,EAAGS,CAAE,EAG1BY,EAAIrB,EAAMS,CAAE,EACNE,EAAI,EAAGA,EAAIU,EAAE,OAAQV,IAC1B,GAAKU,EAAGV,CAAE,IAAMD,EACf,MAAO,GAITW,EAAE,KAAMX,CAAI,CACb,CACA,MAAO,EACR,CAOA,SAASJ,GAAQ,CAChB,IAAIK,EACJ,IAAMA,EAAI,EAAGA,EAAIX,EAAK,OAAQW,IAC7BX,EAAMW,CAAE,EAAE,OAAS,EAEpBZ,EAAS,CACV,CACD,CAKAxC,EAAO,QAAUsC,KCtYjB,IAAAyB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAU,IAmCVC,GAAiBD,GAAQ,EAK7BD,EAAO,QAAUE,KCnBjB,IAAIC,GAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,GAAU,IAKdF,GAAaC,EAAM,UAAWC,EAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isNonNegativeInteger", "format", "validate", "opts", "options", "require_pool", "__commonJSMin", "exports", "module", "pool", "out", "i", "require_bytes_per_element", "__commonJSMin", "exports", "module", "require_factory", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isCollection", "isTypedArrayLike", "isArrayBuffer", "isComplexDataType", "isComplex64Array", "isComplex128Array", "isBooleanArray", "setReadOnly", "setReadOnlyAccessor", "ctors", "reinterpret64", "reinterpret128", "reinterpretBoolean", "resolveGetter", "resolveSetter", "ARRAY_DEFAULTS", "format", "ArrayBuffer", "ceil", "floor", "ceil2", "log2", "min", "defaults", "validate", "createPool", "BYTES_PER_ELEMENT", "DEFAULT_DTYPE", "Complex64Array", "Complex128Array", "BooleanArray", "isCmplx64Array", "arr", "isCmplx128Array", "isBoolArray", "factory", "options", "nbytes", "pool", "opts", "err", "malloc", "calloc", "free", "clear", "getBytes", "arraybuffer", "n", "buf", "i", "typedarray", "ctor", "len", "dtype", "nargs", "out", "set", "get", "tmp", "p", "require_main", "__commonJSMin", "exports", "module", "factory", "typedarraypool", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a2727d6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,333 +0,0 @@ - -{{alias}}( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - Memory is **uninitialized**, which means that the contents of a returned - typed array may contain sensitive contents. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}() - [] - > arr = {{alias}}( 'float32' ) - [] - - -{{alias}}( length[, dtype] ) - Returns an uninitialized typed array having a specified length from a typed - array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > arr = {{alias}}( 5, 'int32' ) - - - -{{alias}}( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - This method shares the same security vulnerabilities mentioned above. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc() - - > arr = {{alias}}.malloc( 'float32' ) - - - -{{alias}}.malloc( length[, dtype] ) - Returns a typed array having a specified length from a typed array memory - pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc( 5 ) - - > arr = {{alias}}.malloc( 5, 'int32' ) - - - -{{alias}}.malloc( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}.malloc( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.calloc( [dtype] ) - Returns a zero-initialized typed array from a typed array memory pool. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc() - [] - > arr = {{alias}}.calloc( 'float32' ) - [] - - -{{alias}}.calloc( length[, dtype] ) - Returns a zero-initialized typed array having a specified length from a - typed array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}.calloc( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}.free( buf ) - Frees a typed array or typed array buffer for use in a future allocation. - - Parameters - ---------- - buf: TypedArray|ArrayBuffer - Typed array or typed array buffer to free. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - - -{{alias}}.clear() - Clears the typed array pool allowing garbage collection of previously - allocated (and currently free) array buffers. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - > {{alias}}.clear(); - - -{{alias}}.highWaterMark - Read-only property returning the pool's high water mark. - - Once a high water mark is reached, typed array allocation fails. - - Examples - -------- - > {{alias}}.highWaterMark - - - -{{alias}}.nbytes - Read-only property returning the total number of allocated bytes. - - The returned value is the total accumulated value. Hence, anytime a pool - must allocate a new array buffer (i.e., more memory), the pool increments - this value. - - The only time this value is decremented is when a pool is cleared. - - This behavior means that, while allocated buffers which are never freed may, - in fact, be garbage collected, they continue to count against the high water - mark limit. - - Accordingly, you should *always* free allocated buffers in order to prevent - the pool from believing that non-freed buffers are continually in use. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.nbytes - - - -{{alias}}.factory( [options] ) - Creates a typed array pool. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.highWaterMark: integer (optional) - Maximum total memory (in bytes) which can be allocated. - - Returns - ------- - fcn: Function - Function for creating typed arrays from a typed array memory pool. - - Examples - -------- - > var pool = {{alias}}.factory(); - > var arr1 = pool( 3, 'float64' ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 4336c42..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,193 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-empty */ -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import typedarraypool = require( './index' ); - - -// TESTS // - -// The function returns a typed array or null... -{ - typedarraypool(); // $ExpectType TypedArrayOrNull - typedarraypool( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the function is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool( true ); // $ExpectError - typedarraypool( false ); // $ExpectError - typedarraypool( null ); // $ExpectError - typedarraypool( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized data type... -{ - typedarraypool( 4, true ); // $ExpectError - typedarraypool( 4, false ); // $ExpectError - typedarraypool( 4, null ); // $ExpectError - typedarraypool( 4, 'abc' ); // $ExpectError - typedarraypool( 4, 123 ); // $ExpectError - typedarraypool( 4, [] ); // $ExpectError - typedarraypool( 4, {} ); // $ExpectError - typedarraypool( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an incorrect number of arguments... -{ - typedarraypool( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `malloc` method which returns a typed array or null... -{ - typedarraypool.malloc(); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.malloc( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `malloc` method is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool.malloc( true ); // $ExpectError - typedarraypool.malloc( false ); // $ExpectError - typedarraypool.malloc( null ); // $ExpectError - typedarraypool.malloc( {} ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.malloc( 4, true ); // $ExpectError - typedarraypool.malloc( 4, false ); // $ExpectError - typedarraypool.malloc( 4, null ); // $ExpectError - typedarraypool.malloc( 4, 'abc' ); // $ExpectError - typedarraypool.malloc( 4, 123 ); // $ExpectError - typedarraypool.malloc( 4, [] ); // $ExpectError - typedarraypool.malloc( 4, {} ); // $ExpectError - typedarraypool.malloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided an incorrect number of arguments... -{ - typedarraypool.malloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `calloc` method which returns a typed array or null... -{ - typedarraypool.calloc(); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `calloc` method is provided a first argument which is not a number... -{ - typedarraypool.calloc( 'abc' ); // $ExpectError - typedarraypool.calloc( true ); // $ExpectError - typedarraypool.calloc( false ); // $ExpectError - typedarraypool.calloc( null ); // $ExpectError - typedarraypool.calloc( {} ); // $ExpectError - typedarraypool.calloc( [] ); // $ExpectError - typedarraypool.calloc( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.calloc( 4, true ); // $ExpectError - typedarraypool.calloc( 4, false ); // $ExpectError - typedarraypool.calloc( 4, null ); // $ExpectError - typedarraypool.calloc( 4, 'abc' ); // $ExpectError - typedarraypool.calloc( 4, 123 ); // $ExpectError - typedarraypool.calloc( 4, [] ); // $ExpectError - typedarraypool.calloc( 4, {} ); // $ExpectError - typedarraypool.calloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided an incorrect number of arguments... -{ - typedarraypool.calloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `factory` method which returns a typed array pool.. -{ - typedarraypool.factory(); // $ExpectType Pool - typedarraypool.factory( { 'highWaterMark': 556 } ); // $ExpectType Pool -} - -// The compiler throws an error if the `factory` method is provided a `highWaterMark` option which is not a number... -{ - typedarraypool.factory( { 'highWaterMark': true } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': false } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': 'abc' } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': null } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': [] } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': {} } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an incorrect number of arguments... -{ - typedarraypool.factory( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` method which returns void... -{ - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.free( arr ); // $ExpectType void -} - -// The compiler throws an error if the `free` method is provided a first argument which is neither a typed array nor array buffer... -{ - typedarraypool.free( true ); // $ExpectError - typedarraypool.free( false ); // $ExpectError - typedarraypool.free( 123 ); // $ExpectError - typedarraypool.free( 'abc' ); // $ExpectError - typedarraypool.free( null ); // $ExpectError - typedarraypool.free( {} ); // $ExpectError - typedarraypool.free( ( x: number ): number => x ); // $ExpectError -} - -// Attached to the main export is a `clear` method which returns void... -{ - typedarraypool.clear(); // $ExpectType void -} - -// The compiler throws an error if the `clear` method is provided arguments... -{ - typedarraypool.clear( {} ); // $ExpectError - typedarraypool.clear( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `highWaterMark` property... -{ - typedarraypool.highWaterMark; // $ExpectType number -} - -// Attached to the main export is a `nbytes` property... -{ - typedarraypool.nbytes; // $ExpectType number -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 24a7846..0000000 --- a/examples/index.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 randu = require( '@stdlib/random-base-randu' ); -var typedarraypool = require( './../lib' ); - -// Create a typed array pool which can allocate at most 1GB: -var typedarray = typedarraypool.factory({ - 'highWaterMark': 1e9 -}); - -// Inspect the pool: -console.log( 'Max bytes: %d', typedarray.highWaterMark ); -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Allocate an array for storing double-precision floating-point numbers: -var arr1 = typedarray( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Fill the array... -var i; -for ( i = 0; i < arr1.length; i++ ) { - arr1[ i ] = randu(); -} - -// Inspect array contents: -console.log( arr1 ); - -// Free the array: -typedarray.free( arr1 ); - -// Allocate another array similar to the previous one: -var arr2 = typedarray( 5, 'float64' ); -// returns - -// Check that we have been returned a new typed array view: -console.log( arr2 === arr1 ); -// => false - -// Inspect array contents: -console.log( arr2 ); - -// Free the array: -typedarray.free( arr2 ); - -// Allocate an initialized array: -var arr3 = typedarray.calloc( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect array contents: -console.log( arr3 ); - -// Free the array: -typedarray.free( arr3 ); - -// Clear the pool: -typedarray.clear(); - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 4dc8736..8298bf3 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike, RealOrComplexTypedArray, BooleanArray, NumericDataType as DataType } from '@stdlib/types/array'; import ArrayBuffer = require( '@stdlib/array-buffer' ); diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..1857d00 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-booleanarray@v0.0.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.2.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.2.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.1-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-setter@v0.2.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/array-defaults@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.1-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.2.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.2.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.2.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.2.1-esm/index.mjs";import M from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.2.2-esm/index.mjs";import W from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";var H={bool:1,float64:8,float32:4,int16:2,int32:4,int8:1,uint16:2,uint32:4,uint8:1,uint8c:1,complex64:8,complex128:16},T=g.get("dtypes.default"),L=h("complex64"),P=h("complex128"),V=h("bool");function Y(e){return e instanceof L}function q(e){return e instanceof P}function z(e){return e instanceof V}function A(g){var L,P,V,A;if(V={highWaterMark:9007199254740992},arguments.length&&(A=function(e,t){return W(t)?E(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(u("01H2t","highWaterMark",e.highWaterMark)):null:new TypeError(u("01H2V",t))}(V,g),A))throw A;return P=function(e){var t,r;for(t=[],r=0;r0){for(t=y(k(e.byteLength)),t=M(P.length-1,t),r=P[t],s=0;sV.highWaterMark?null:(t=new b(e),L+=e,t)}(w(t)*H[r]))?s:new e(s,0,t)}function C(){var e,i,n,a,g,b,x,y,w;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:T,null===(n=h(i)))throw new TypeError(u("01H2Y",i));if(e<=0)return new n(0);if(r(arguments[0]))return B(n,arguments[0],i);if(s(arguments[0])){if(y=(a=arguments[0]).length,d(a)?a=j(a,0):m(a)?a=p(a,0):l(a)?a=f(a,0):o(i)&&(y/=2),null===(g=B(n,y,i)))return g;if(q(g)||Y(g)||z(g))return g.set(a),g;for(x=c(a),b=v(g),w=0;w[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '01H2Y', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( isBooleanArray( arr ) ) {\n\t\t\t\tarr = reinterpretBoolean( arr, 0 );\n\t\t\t} else if ( isComplexDataType( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) || isBoolArray( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = resolveGetter( arr );\n\t\t\tset = resolveSetter( out );\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '01H2r', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else if ( isBoolArray( out ) ) {\n\t\t\t\ttmp = reinterpretBoolean( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( '01H2s', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'highWaterMark': 1024\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '01H2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'highWaterMark' ) ) {\n\t\topts.highWaterMark = options.highWaterMark;\n\t\tif ( !isNonNegativeInteger( opts.highWaterMark ) ) {\n\t\t\treturn new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Initializes a cache for pooled typed array buffers.\n*\n* @private\n* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size\n* @returns {ArrayArray} initialized cache\n*/\nfunction pool( n ) {\n\tvar out;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < n+1; i++ ) {\n\t\tout.push( [] );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default pool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DEFAULT_DTYPE","ARRAY_DEFAULTS","get","Complex64Array","ctors","Complex128Array","BooleanArray","isCmplx64Array","arr","isCmplx128Array","isBoolArray","factory","options","nbytes","pool","opts","err","highWaterMark","arguments","length","isObject","hasOwnProp","isNonNegativeInteger","TypeError","format","validate","n","out","i","push","createPool","ceil","log2","setReadOnly","malloc","nargs","tmp","reinterpret128","reinterpret64","reinterpretBoolean","buf","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","setReadOnlyAccessor","typedarray","ctor","len","dtype","pop","ArrayBuffer","arraybuffer","ceil2","BYTES_PER_ELEMENT","set","isString","isCollection","isComplex128Array","isComplex64Array","isBooleanArray","isComplexDataType","resolveGetter","resolveSetter","typedarraypool","main"],"mappings":";;wzFAuDIA,EAAgBC,EAAeC,IAAK,kBACpCC,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cACzBE,EAAeF,EAAO,QAY1B,SAASG,EAAgBC,GACxB,OAASA,aAAeL,CACzB,CASA,SAASM,EAAiBD,GACzB,OAASA,aAAeH,CACzB,CASA,SAASK,EAAaF,GACrB,OAASA,aAAeF,CACzB,CA6BA,SAASK,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,EChGO,CACNE,cAAiB,kBDgGbC,UAAUC,SACdH,EElFF,SAAmBD,EAAMH,GACxB,OAAMQ,EAAUR,GAGXS,EAAYT,EAAS,mBACzBG,EAAKE,cAAgBL,EAAQK,eACvBK,EAAsBP,EAAKE,gBACzB,IAAIM,UAAWC,EAAQ,QAAS,gBAAiBT,EAAKE,gBAGxD,KARC,IAAIM,UAAWC,EAAQ,QAASZ,GASzC,CFuEQa,CAAUV,EAAMH,GACjBI,GACJ,MAAMA,EAaR,OAVAF,EG3GD,SAAeY,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,CHkGQG,CAAYC,EAAMC,EAAMjB,EAAKE,iBACpCJ,EAAS,EAEToB,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,UAiKrB,WACC,IAAIC,EACAR,EACAS,EACAR,EAEJO,EAAQjB,UAAUC,OAEjBQ,EADc,IAAVQ,EACED,IACe,IAAVC,EACLD,EAAQhB,UAAW,IAEnBgB,EAAQhB,UAAW,GAAKA,UAAW,IAE1C,GAAa,OAARS,EAWJ,IARCS,EADI3B,EAAiBkB,GACfU,EAAgBV,EAAK,GAChBpB,EAAgBoB,GACrBW,EAAeX,EAAK,GACfjB,EAAaiB,GAClBY,EAAoBZ,EAAK,GAEzBA,EAEDC,EAAI,EAAGA,EAAIQ,EAAIjB,OAAQS,IAC5BQ,EAAKR,GAAM,EAGb,OAAOD,CACP,IA9LDM,EAAaC,EAAQ,QA4MrB,SAAeM,GACd,IAAId,EACAe,EACAb,EACJ,GAAKc,EAAkBF,IAASA,EAAIG,OACnCH,EAAMA,EAAIG,YACJ,IAAMC,EAAeJ,GAC3B,MAAM,IAAIjB,UAAWC,EAAQ,QAASgB,IAEvC,GAAKA,EAAIK,WAAa,EAAI,CAQzB,IAPAnB,EAAIoB,EAAOd,EAAMQ,EAAIK,aAGrBnB,EAAIqB,EAAKjC,EAAKK,OAAO,EAAGO,GAGxBe,EAAI3B,EAAMY,GACJE,EAAI,EAAGA,EAAIa,EAAEtB,OAAQS,IAC1B,GAAKa,EAAGb,KAAQY,EACf,OAAO,EAITC,EAAEZ,KAAMW,EACR,CACD,OAAO,CACP,IArODP,EAAaC,EAAQ,SA4OrB,WACC,IAAIN,EACJ,IAAMA,EAAI,EAAGA,EAAId,EAAKK,OAAQS,IAC7Bd,EAAMc,GAAIT,OAAS,EAEpBN,EAAS,CACT,IAjPDoB,EAAaC,EAAQ,gBAAiBnB,EAAKE,eAC3C+B,EAAqBd,EAAQ,UAU7B,WACC,OAAOrB,CACP,IAVMqB,EAmDP,SAASe,EAAYC,EAAMC,EAAKC,GAC/B,IAAIZ,EACJ,OAAa,IAARW,EACG,IAAID,EAAM,GAGL,QADbV,EArCD,SAAsBd,GACrB,IAAIc,EACAZ,EAMJ,OAHAA,EAAII,EAAMN,IAGDZ,EAAKK,QAAUL,EAAMc,GAAIT,OAC1BL,EAAMc,GAAIyB,MAGbxC,EAAOa,EAAIX,EAAKE,cACb,MAERuB,EAAM,IAAIc,EAAa5B,GAGvBb,GAAUa,EAEHc,EACP,CAgBMe,CAAaC,EAAOL,GAAMM,EAAmBL,KAE3CZ,EAED,IAAIU,EAAMV,EAAK,EAAGW,EACzB,CAkBD,SAASjB,IACR,IAAIC,EACAiB,EACAF,EACA1C,EACAmB,EACA+B,EACAxD,EACAiD,EACAvB,EAUJ,GALCwB,GAHDjB,EAAQjB,UAAUC,SACJwC,EAAUzC,UAAWiB,EAAM,IAEhCjB,UADRiB,GAAS,GAGDnC,EAGK,QADdkD,EAAO9C,EAAOgD,IAEb,MAAM,IAAI7B,UAAWC,EAAQ,QAAS4B,IAEvC,GAAKjB,GAAS,EACb,OAAO,IAAIe,EAAM,GAGlB,GAAK5B,EAAsBJ,UAAW,IACrC,OAAO+B,EAAYC,EAAMhC,UAAW,GAAKkC,GAG1C,GAAKQ,EAAc1C,UAAW,IAAQ,CAcrC,GAZAiC,GADA3C,EAAMU,UAAW,IACPC,OACL0C,EAAmBrD,GACvBA,EAAM6B,EAAgB7B,EAAK,GAChBsD,EAAkBtD,GAC7BA,EAAM8B,EAAe9B,EAAK,GACfuD,EAAgBvD,GAC3BA,EAAM+B,EAAoB/B,EAAK,GACpBwD,EAAmBZ,KAE9BD,GAAO,GAGK,QADbxB,EAAMsB,EAAYC,EAAMC,EAAKC,IAE5B,OAAOzB,EAER,GAAKlB,EAAiBkB,IAASpB,EAAgBoB,IAASjB,EAAaiB,GAEpE,OADAA,EAAI+B,IAAKlD,GACFmB,EAKR,IAFAzB,EAAM+D,EAAezD,GACrBkD,EAAMQ,EAAevC,GACfC,EAAI,EAAGA,EAAIuB,EAAKvB,IACrB8B,EAAK/B,EAAKC,EAAG1B,EAAKM,EAAKoB,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,QAASN,UAAW,IACjD,CAoGF,CIxUG,IAACiD,EAAiBxD,ICPrBsB,EAAAmC,EAAA,UAAAzD"} \ No newline at end of file diff --git a/lib/bytes_per_element.json b/lib/bytes_per_element.json deleted file mode 100644 index 30f02fc..0000000 --- a/lib/bytes_per_element.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "bool": 1, - "float64": 8, - "float32": 4, - "int16": 2, - "int32": 4, - "int8": 1, - "uint16": 2, - "uint32": 4, - "uint8": 1, - "uint8c": 1, - "complex64": 8, - "complex128": 16 -} diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index a421711..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +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'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'highWaterMark': 9007199254740992 - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 7f297ce..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,391 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' ); -var isComplex64Array = require( '@stdlib/assert-is-complex64array' ); -var isComplex128Array = require( '@stdlib/assert-is-complex128array' ); -var isBooleanArray = require( '@stdlib/assert-is-booleanarray' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var ctors = require( '@stdlib/array-typed-ctors' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var resolveSetter = require( '@stdlib/array-base-resolve-setter' ); -var ARRAY_DEFAULTS = require( '@stdlib/array-defaults' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil = require( '@stdlib/math-base-special-ceil' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); -var log2 = require( '@stdlib/math-base-special-log2' ); -var min = require( '@stdlib/math-base-special-min' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var createPool = require( './pool.js' ); -var BYTES_PER_ELEMENT = require( './bytes_per_element.json' ); - - -// VARIABLES // - -var DEFAULT_DTYPE = ARRAY_DEFAULTS.get( 'dtypes.default' ); -var Complex64Array = ctors( 'complex64' ); -var Complex128Array = ctors( 'complex128' ); -var BooleanArray = ctors( 'bool' ); - - -// FUNCTIONS // - -/** -* Tests whether an array is a single-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a single-precision complex floating-point number array -*/ -function isCmplx64Array( arr ) { - return ( arr instanceof Complex64Array ); -} - -/** -* Tests whether an array is a double-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a double-precision complex floating-point number array -*/ -function isCmplx128Array( arr ) { - return ( arr instanceof Complex128Array ); -} - -/** -* Tests whether an array is a boolean array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a boolean array -*/ -function isBoolArray( arr ) { - return ( arr instanceof BooleanArray ); -} - - -// MAIN // - -/** -* Creates a typed array pool. -* -* @param {Options} [options] - pool options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} allocator -* -* @example -* var typedarraypool = factory(); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -function factory( options ) { - var nbytes; - var pool; - var opts; - var err; - - opts = defaults(); - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - pool = createPool( ceil( log2( opts.highWaterMark ) ) ); - nbytes = 0; - - setReadOnly( malloc, 'malloc', malloc ); // circular reference - setReadOnly( malloc, 'calloc', calloc ); - setReadOnly( malloc, 'free', free ); - setReadOnly( malloc, 'clear', clear ); - setReadOnly( malloc, 'highWaterMark', opts.highWaterMark ); - setReadOnlyAccessor( malloc, 'nbytes', getBytes ); - - return malloc; - - /** - * Returns the number of allocated bytes. - * - * @private - * @returns {NonNegativeInteger} number of allocated bytes - */ - function getBytes() { - return nbytes; - } - - /** - * Returns an array buffer. - * - * @private - * @param {NonNegativeInteger} n - number of bytes - * @returns {(ArrayBuffer|null)} array buffer or null - */ - function arraybuffer( n ) { - var buf; - var i; - - // Convert the number of bytes to an index in our pool table: - i = log2( n ); - - // If we already have an available array buffer, use it... - if ( i < pool.length && pool[ i ].length ) { - return pool[ i ].pop(); - } - // Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate... - if ( nbytes+n > opts.highWaterMark ) { - return null; - } - buf = new ArrayBuffer( n ); - - // Update the running counter of allocated bytes: - nbytes += n; - - return buf; - } - - /** - * Returns a typed array. - * - * @private - * @param {Function} ctor - typed array constructor - * @param {NonNegativeInteger} len - view length - * @param {string} dtype - data type - * @returns {(TypedArray|null)} typed array or null - */ - function typedarray( ctor, len, dtype ) { - var buf; - if ( len === 0 ) { - return new ctor( 0 ); - } - buf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] ); - if ( buf === null ) { - return buf; - } - return new ctor( buf, 0, len ); - } - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length or an array-like object - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function malloc() { - var nargs; - var dtype; - var ctor; - var arr; - var out; - var set; - var get; - var len; - var i; - - nargs = arguments.length; - if ( nargs && isString( arguments[ nargs-1 ] ) ) { - nargs -= 1; - dtype = arguments[ nargs ]; - } else { - dtype = DEFAULT_DTYPE; - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( '01H2Y', dtype ) ); - } - if ( nargs <= 0 ) { - return new ctor( 0 ); - } - // Check if provided a typed array length... - if ( isNonNegativeInteger( arguments[ 0 ] ) ) { - return typedarray( ctor, arguments[ 0 ], dtype ); - } - // Check if provided an array-like object containing data elements... - if ( isCollection( arguments[ 0 ] ) ) { - arr = arguments[ 0 ]; - len = arr.length; - if ( isComplex128Array( arr ) ) { - arr = reinterpret128( arr, 0 ); - } else if ( isComplex64Array( arr ) ) { - arr = reinterpret64( arr, 0 ); - } else if ( isBooleanArray( arr ) ) { - arr = reinterpretBoolean( arr, 0 ); - } else if ( isComplexDataType( dtype ) ) { - // Assume we've been provided an array of interleaved real and imaginary components... - len /= 2; - } - out = typedarray( ctor, len, dtype ); - if ( out === null ) { - return out; - } - if ( isCmplx128Array( out ) || isCmplx64Array( out ) || isBoolArray( out ) ) { - out.set( arr ); - return out; - } - // Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other "unsafe" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things... - get = resolveGetter( arr ); - set = resolveSetter( out ); - for ( i = 0; i < len; i++ ) { - set( out, i, get( arr, i ) ); - } - return out; - } - throw new TypeError( format( '01H2r', arguments[ 0 ] ) ); - } - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {NonNegativeInteger} [len=0] - array length - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function calloc() { - var nargs; - var out; - var tmp; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - out = malloc(); - } else if ( nargs === 1 ) { - out = malloc( arguments[ 0 ] ); - } else { - out = malloc( arguments[ 0 ], arguments[ 1 ] ); - } - if ( out !== null ) { - // Initialize the memory... - if ( isCmplx128Array( out ) ) { - tmp = reinterpret128( out, 0 ); - } else if ( isCmplx64Array( out ) ) { - tmp = reinterpret64( out, 0 ); - } else if ( isBoolArray( out ) ) { - tmp = reinterpretBoolean( out, 0 ); - } else { - tmp = out; - } - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = 0.0; - } - } - return out; - } - - /** - * Frees a typed array or typed array buffer. - * - * ## Notes - * - * - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., "freeing" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool. - * - * @private - * @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free - * @throws {TypeError} must provide a typed array or typed array buffer - * @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed - */ - function free( buf ) { - var n; - var p; - var i; - if ( isTypedArrayLike( buf ) && buf.buffer ) { - buf = buf.buffer; - } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( '01H2s', buf ) ); - } - if ( buf.byteLength > 0 ) { - n = floor( log2( buf.byteLength ) ); - - // Prohibit "freeing" array buffers which would potentially allow users to circumvent high water mark limits: - n = min( pool.length-1, n ); - - // Ensure that we do not attempt to free the same buffer more than once... - p = pool[ n ]; - for ( i = 0; i < p.length; i++ ) { - if ( p[ i ] === buf ) { - return false; - } - } - // Add the buffer to our pool of free buffers: - p.push( buf ); - } - return true; - } - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @private - */ - function clear() { - var i; - for ( i = 0; i < pool.length; i++ ) { - pool[ i ].length = 0; - } - nbytes = 0; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6c12a4e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Typed array pool. -* -* @module @stdlib/array-pool -* -* @example -* var typedarraypool = require( '@stdlib/array-pool' ); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8f69ee3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,63 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @name typedarraypool -* @type {Function} -* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a valid array length or an array-like object -* @throws {TypeError} must provide a recognized data type -* @returns {(TypedArray|null)} typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -var typedarraypool = factory(); - - -// EXPORTS // - -module.exports = typedarraypool; diff --git a/lib/pool.js b/lib/pool.js deleted file mode 100644 index 5abd287..0000000 --- a/lib/pool.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Initializes a cache for pooled typed array buffers. -* -* @private -* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size -* @returns {ArrayArray} initialized cache -*/ -function pool( n ) { - var out; - var i; - - out = []; - for ( i = 0; i < n+1; i++ ) { - out.push( [] ); - } - return out; -} - - -// EXPORTS // - -module.exports = pool; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index da746bb..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'highWaterMark': 1024 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '01H2V', options ) ); - } - if ( hasOwnProp( options, 'highWaterMark' ) ) { - opts.highWaterMark = options.highWaterMark; - if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 748ec44..ce31461 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Typed array pool.", "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,83 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-is-complex-floating-point-data-type": "^0.2.1", - "@stdlib/array-base-resolve-getter": "^0.2.1", - "@stdlib/array-base-resolve-setter": "^0.2.1", - "@stdlib/array-buffer": "^0.2.1", - "@stdlib/array-defaults": "^0.2.1", - "@stdlib/array-typed-ctors": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-arraybuffer": "^0.2.1", - "@stdlib/assert-is-booleanarray": "^0.0.1", - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-complex128array": "^0.2.1", - "@stdlib/assert-is-complex64array": "^0.2.1", - "@stdlib/assert-is-nonnegative-integer": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/assert-is-string": "^0.2.1", - "@stdlib/assert-is-typed-array-like": "^0.2.1", - "@stdlib/math-base-special-ceil": "^0.2.1", - "@stdlib/math-base-special-ceil2": "^0.2.1", - "@stdlib/math-base-special-floor": "^0.2.2", - "@stdlib/math-base-special-log2": "^0.2.1", - "@stdlib/math-base-special-min": "^0.2.2", - "@stdlib/strided-base-reinterpret-boolean": "^0.0.1", - "@stdlib/strided-base-reinterpret-complex128": "^0.2.1", - "@stdlib/strided-base-reinterpret-complex64": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.2", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-bool": "^0.0.1", - "@stdlib/array-complex128": "^0.2.1", - "@stdlib/array-complex64": "^0.2.1", - "@stdlib/array-float32": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/array-int16": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/array-int8": "^0.2.1", - "@stdlib/array-uint16": "^0.2.1", - "@stdlib/array-uint32": "^0.2.1", - "@stdlib/array-uint8": "^0.2.1", - "@stdlib/array-uint8c": "^0.2.1", - "@stdlib/assert-instance-of": "^0.2.1", - "@stdlib/assert-is-complex-typed-array": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-typed-array": "^0.2.1", - "@stdlib/boolean-ctor": "^0.2.1", - "@stdlib/complex-float32-ctor": "^0.0.1", - "@stdlib/complex-float32-imag": "github:stdlib-js/complex-float32-imag#main", - "@stdlib/complex-float32-real": "github:stdlib-js/complex-float32-real#main", - "@stdlib/complex-float64-ctor": "^0.0.1", - "@stdlib/complex-float64-imag": "github:stdlib-js/complex-float64-imag#main", - "@stdlib/complex-float64-real": "github:stdlib-js/complex-float64-real#main", - "@stdlib/math-base-special-pow": "^0.2.1", - "@stdlib/random-base-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9bac0b8 --- /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.factory.js b/test/test.factory.js deleted file mode 100644 index 95d35c9..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,2401 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var real = require( '@stdlib/complex-float64-real' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imag = require( '@stdlib/complex-float64-imag' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function (no options)', function test( t ) { - t.strictEqual( typeof factory(), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - t.strictEqual( typeof factory( {} ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided a `highWaterMark` option which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (length)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a function which returns a typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=bool)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, length)', function test( t ) { - var typedarraypool = factory(); - var arr; - - arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=bool, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=bool, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ true, false, false, true ]; - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( v, arr[ 0 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( v, arr[ 1 ], 'returns expected value' ); - - v = out.get( 2 ); - t.strictEqual( v, arr[ 2 ], 'returns expected value' ); - - v = out.get( 3 ); - t.strictEqual( v, arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=bool, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Uint8Array( 0 ); - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8Array( [ 1, 0, 0, 1 ] ); - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( v, true, 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( v, false, 'returns expected value' ); - - v = out.get( 2 ); - t.strictEqual( v, false, 'returns expected value' ); - - v = out.get( 3 ); - t.strictEqual( v, true, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a `malloc` method which is a circular reference', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=bool)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=bool, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'bool' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( Boolean( i%2 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( v, false, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - var buf; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the returned function is a property which returns the pool\'s high water mark', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function supports specifying a high water mark which limits the total amount of memory a pool can allocate', function test( t ) { - var typedarraypool; - var arr1; - var arr2; - - typedarraypool = factory({ - 'highWaterMark': 64 // bytes - }); - - typedarraypool.clear(); - - arr1 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr1.length, 8, 'returns expected value' ); - t.strictEqual( arr1.byteLength, 64, 'returns expected value' ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - typedarraypool.free( arr1 ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Create an array which is less than or equal to the high water mark: - arr2 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr2.length, 8, 'returns expected value' ); - t.strictEqual( arr2.byteLength, 64, 'returns expected value' ); - - typedarraypool.free( arr2 ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a property which returns the total number of accumulated bytes', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var typedarraypool; - var arrs; - var i; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index a4778b2..0000000 --- a/test/test.js +++ /dev/null @@ -1,1935 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var real = require( '@stdlib/complex-float64-real' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imag = require( '@stdlib/complex-float64-imag' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var typedarraypool = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=bool)', function test( t ) { - var arr = typedarraypool( 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=bool, length)', function test( t ) { - var arr = typedarraypool( 10, 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=bool, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ true, false, false, true ]; - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( v, arr[ 0 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( v, arr[ 1 ], 'returns expected value' ); - - v = out.get( 2 ); - t.strictEqual( v, arr[ 2 ], 'returns expected value' ); - - v = out.get( 3 ); - t.strictEqual( v, arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=bool, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Uint8Array( 0 ); - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8Array( [ 1, 0, 0, 1 ] ); - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( v, true, 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( v, false, 'returns expected value' ); - - v = out.get( 2 ); - t.strictEqual( v, false, 'returns expected value' ); - - v = out.get( 3 ); - t.strictEqual( v, true, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=bool)', function test( t ) { - var arr = typedarraypool.calloc( 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=bool, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'bool' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( Boolean( i%2 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( v, false, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -}); From 7388fce76be066733b04a95f2451ffd128927d54 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 01:45:50 +0000 Subject: [PATCH 098/103] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index ce4ba27..7f297ce 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -38,7 +38,7 @@ var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); var resolveSetter = require( '@stdlib/array-base-resolve-setter' ); var ARRAY_DEFAULTS = require( '@stdlib/array-defaults' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ArrayBuffer = require( '@stdlib/array-buffer' ); var ceil = require( '@stdlib/math-base-special-ceil' ); var floor = require( '@stdlib/math-base-special-floor' ); @@ -243,7 +243,7 @@ function factory( options ) { } ctor = ctors( dtype ); if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '01H2Y', dtype ) ); } if ( nargs <= 0 ) { return new ctor( 0 ); @@ -282,7 +282,7 @@ function factory( options ) { } return out; } - throw new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) ); + throw new TypeError( format( '01H2r', arguments[ 0 ] ) ); } /** @@ -350,7 +350,7 @@ function factory( options ) { if ( isTypedArrayLike( buf ) && buf.buffer ) { buf = buf.buffer; } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) ); + throw new TypeError( format( '01H2s', buf ) ); } if ( buf.byteLength > 0 ) { n = floor( log2( buf.byteLength ) ); diff --git a/lib/validate.js b/lib/validate.js index ce54890..da746bb 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '01H2V', options ) ); } if ( hasOwnProp( options, 'highWaterMark' ) ) { opts.highWaterMark = options.highWaterMark; if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) ); + return new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) ); } } return null; diff --git a/package.json b/package.json index b66a8e5..2945498 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "@stdlib/strided-base-reinterpret-boolean": "^0.0.2", "@stdlib/strided-base-reinterpret-complex128": "^0.2.2", "@stdlib/strided-base-reinterpret-complex64": "^0.2.1", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From 1ec827adb955cb9049b91ac21f2d3e3ebf64b596 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 01:57:18 +0000 Subject: [PATCH 099/103] Remove files --- index.d.ts | 359 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5206 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 8298bf3..0000000 --- a/index.d.ts +++ /dev/null @@ -1,359 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike, RealOrComplexTypedArray, BooleanArray, NumericDataType as DataType } from '@stdlib/types/array'; -import ArrayBuffer = require( '@stdlib/array-buffer' ); - -/** -* Typed array or null. -*/ -type TypedArrayOrNull = RealOrComplexTypedArray | BooleanArray | null; - -/** -* Interface defining pool options. -*/ -interface Options { - /** - * Maximum total memory which can be allocated. - */ - highWaterMark?: number; -} - -/** -* Pool interface. -*/ -interface Pool { - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr = typedarraypool(); - * // returns [] - * - * @example - * var arr = typedarraypool( 'float32' ); - * // returns [] - */ - ( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * // Allocate an array of doubles: - * var arr = typedarraypool( 5, 'float64' ); - * // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * typedarraypool.free( arr ); - * - * @example - * var arr1 = typedarraypool( [ 0.5, 0.5, 0.5 ] ); - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * @example - * var arr1 = [ 0.5, 0.5, 0.5 ]; - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - */ - ( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc(); - * // returns [] - * - * var arr2 = typedarraypool.calloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param length - typed array length - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc( 5 ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * var arr2 = typedarraypool.calloc( 5, 'uint8' ); - * // returns [ 0, 0, 0, 0, 0 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( length: number, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc(); - * // returns [] - * - * var arr2 = typedarraypool.malloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc( 5 ); - * // returns - * - * var arr2 = typedarraypool.malloc( 5, 'uint8' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 5.0, -3.0, 2.0 ] ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr2 = typedarraypool.malloc( arr1 ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr3 = typedarraypool.malloc( arr1, 'int32' ); - * // returns [ 5, -3, 2 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * typedarraypool.free( arr3 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ] ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * var arr2 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ], 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Frees a typed array or typed array buffer for use in a future allocation. - * - * @param buf - typed array or typed array buffer to free - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array for use in a future allocation: - * typedarraypool.free( arr ); - * - * // Create another typed array: - * arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array buffer for use in a future allocation: - * typedarraypool.free( arr.buffer ); - */ - free( buf: RealOrComplexTypedArray | BooleanArray | ArrayBuffer ): void; - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr ); - * - * // ... - * - * // Clear all freed buffers: - * typedarraypool.clear(); - */ - clear(): void; - - /** - * Read-only property returning the pool's high water mark. - * - * ## Notes - * - * - Once a high water mark is reached, typed array allocation fails. - * - * @example - * var limit = typedarraypool.highWaterMark; - * // returns - */ - readonly highWaterMark: number; - - /** - * Read-only property returning the total number of allocated bytes. - * - * @example - * var arr = typedarraypool( 5, 'float64' ); - * - * var nbytes = typedarraypool.nbytes; - * // returns - */ - readonly nbytes: number; - - /** - * Creates a typed array pool. - * - * @param options - pool options - * @param options.highWaterMark - maximum total memory which can be allocated - * @throws must provide valid options - * @returns allocator - * - * @example - * var allocator = typedarraypool.factory(); - * - * // Allocate an array of doubles: - * var arr = allocator( 5, 'float64' ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * allocator.free( arr ); - */ - factory( options?: Options ): Pool; -} - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @param arg - an array length or an array-like object -* @param dtype - data type (default: 'float64') -* @returns typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -declare var typedarraypool: Pool; - - -// EXPORTS // - -export = typedarraypool; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 1857d00..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-booleanarray@v0.0.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.2.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.2.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.1-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-setter@v0.2.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/array-defaults@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.1-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.2.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.2.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.2.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.2.1-esm/index.mjs";import M from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.2.2-esm/index.mjs";import W from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";var H={bool:1,float64:8,float32:4,int16:2,int32:4,int8:1,uint16:2,uint32:4,uint8:1,uint8c:1,complex64:8,complex128:16},T=g.get("dtypes.default"),L=h("complex64"),P=h("complex128"),V=h("bool");function Y(e){return e instanceof L}function q(e){return e instanceof P}function z(e){return e instanceof V}function A(g){var L,P,V,A;if(V={highWaterMark:9007199254740992},arguments.length&&(A=function(e,t){return W(t)?E(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(u("01H2t","highWaterMark",e.highWaterMark)):null:new TypeError(u("01H2V",t))}(V,g),A))throw A;return P=function(e){var t,r;for(t=[],r=0;r0){for(t=y(k(e.byteLength)),t=M(P.length-1,t),r=P[t],s=0;sV.highWaterMark?null:(t=new b(e),L+=e,t)}(w(t)*H[r]))?s:new e(s,0,t)}function C(){var e,i,n,a,g,b,x,y,w;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:T,null===(n=h(i)))throw new TypeError(u("01H2Y",i));if(e<=0)return new n(0);if(r(arguments[0]))return B(n,arguments[0],i);if(s(arguments[0])){if(y=(a=arguments[0]).length,d(a)?a=j(a,0):m(a)?a=p(a,0):l(a)?a=f(a,0):o(i)&&(y/=2),null===(g=B(n,y,i)))return g;if(q(g)||Y(g)||z(g))return g.set(a),g;for(x=c(a),b=v(g),w=0;w[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '01H2Y', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( isBooleanArray( arr ) ) {\n\t\t\t\tarr = reinterpretBoolean( arr, 0 );\n\t\t\t} else if ( isComplexDataType( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) || isBoolArray( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = resolveGetter( arr );\n\t\t\tset = resolveSetter( out );\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '01H2r', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else if ( isBoolArray( out ) ) {\n\t\t\t\ttmp = reinterpretBoolean( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( '01H2s', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'highWaterMark': 1024\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '01H2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'highWaterMark' ) ) {\n\t\topts.highWaterMark = options.highWaterMark;\n\t\tif ( !isNonNegativeInteger( opts.highWaterMark ) ) {\n\t\t\treturn new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Initializes a cache for pooled typed array buffers.\n*\n* @private\n* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size\n* @returns {ArrayArray} initialized cache\n*/\nfunction pool( n ) {\n\tvar out;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < n+1; i++ ) {\n\t\tout.push( [] );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default pool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DEFAULT_DTYPE","ARRAY_DEFAULTS","get","Complex64Array","ctors","Complex128Array","BooleanArray","isCmplx64Array","arr","isCmplx128Array","isBoolArray","factory","options","nbytes","pool","opts","err","highWaterMark","arguments","length","isObject","hasOwnProp","isNonNegativeInteger","TypeError","format","validate","n","out","i","push","createPool","ceil","log2","setReadOnly","malloc","nargs","tmp","reinterpret128","reinterpret64","reinterpretBoolean","buf","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","setReadOnlyAccessor","typedarray","ctor","len","dtype","pop","ArrayBuffer","arraybuffer","ceil2","BYTES_PER_ELEMENT","set","isString","isCollection","isComplex128Array","isComplex64Array","isBooleanArray","isComplexDataType","resolveGetter","resolveSetter","typedarraypool","main"],"mappings":";;wzFAuDIA,EAAgBC,EAAeC,IAAK,kBACpCC,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cACzBE,EAAeF,EAAO,QAY1B,SAASG,EAAgBC,GACxB,OAASA,aAAeL,CACzB,CASA,SAASM,EAAiBD,GACzB,OAASA,aAAeH,CACzB,CASA,SAASK,EAAaF,GACrB,OAASA,aAAeF,CACzB,CA6BA,SAASK,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,EChGO,CACNE,cAAiB,kBDgGbC,UAAUC,SACdH,EElFF,SAAmBD,EAAMH,GACxB,OAAMQ,EAAUR,GAGXS,EAAYT,EAAS,mBACzBG,EAAKE,cAAgBL,EAAQK,eACvBK,EAAsBP,EAAKE,gBACzB,IAAIM,UAAWC,EAAQ,QAAS,gBAAiBT,EAAKE,gBAGxD,KARC,IAAIM,UAAWC,EAAQ,QAASZ,GASzC,CFuEQa,CAAUV,EAAMH,GACjBI,GACJ,MAAMA,EAaR,OAVAF,EG3GD,SAAeY,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,CHkGQG,CAAYC,EAAMC,EAAMjB,EAAKE,iBACpCJ,EAAS,EAEToB,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,UAiKrB,WACC,IAAIC,EACAR,EACAS,EACAR,EAEJO,EAAQjB,UAAUC,OAEjBQ,EADc,IAAVQ,EACED,IACe,IAAVC,EACLD,EAAQhB,UAAW,IAEnBgB,EAAQhB,UAAW,GAAKA,UAAW,IAE1C,GAAa,OAARS,EAWJ,IARCS,EADI3B,EAAiBkB,GACfU,EAAgBV,EAAK,GAChBpB,EAAgBoB,GACrBW,EAAeX,EAAK,GACfjB,EAAaiB,GAClBY,EAAoBZ,EAAK,GAEzBA,EAEDC,EAAI,EAAGA,EAAIQ,EAAIjB,OAAQS,IAC5BQ,EAAKR,GAAM,EAGb,OAAOD,CACP,IA9LDM,EAAaC,EAAQ,QA4MrB,SAAeM,GACd,IAAId,EACAe,EACAb,EACJ,GAAKc,EAAkBF,IAASA,EAAIG,OACnCH,EAAMA,EAAIG,YACJ,IAAMC,EAAeJ,GAC3B,MAAM,IAAIjB,UAAWC,EAAQ,QAASgB,IAEvC,GAAKA,EAAIK,WAAa,EAAI,CAQzB,IAPAnB,EAAIoB,EAAOd,EAAMQ,EAAIK,aAGrBnB,EAAIqB,EAAKjC,EAAKK,OAAO,EAAGO,GAGxBe,EAAI3B,EAAMY,GACJE,EAAI,EAAGA,EAAIa,EAAEtB,OAAQS,IAC1B,GAAKa,EAAGb,KAAQY,EACf,OAAO,EAITC,EAAEZ,KAAMW,EACR,CACD,OAAO,CACP,IArODP,EAAaC,EAAQ,SA4OrB,WACC,IAAIN,EACJ,IAAMA,EAAI,EAAGA,EAAId,EAAKK,OAAQS,IAC7Bd,EAAMc,GAAIT,OAAS,EAEpBN,EAAS,CACT,IAjPDoB,EAAaC,EAAQ,gBAAiBnB,EAAKE,eAC3C+B,EAAqBd,EAAQ,UAU7B,WACC,OAAOrB,CACP,IAVMqB,EAmDP,SAASe,EAAYC,EAAMC,EAAKC,GAC/B,IAAIZ,EACJ,OAAa,IAARW,EACG,IAAID,EAAM,GAGL,QADbV,EArCD,SAAsBd,GACrB,IAAIc,EACAZ,EAMJ,OAHAA,EAAII,EAAMN,IAGDZ,EAAKK,QAAUL,EAAMc,GAAIT,OAC1BL,EAAMc,GAAIyB,MAGbxC,EAAOa,EAAIX,EAAKE,cACb,MAERuB,EAAM,IAAIc,EAAa5B,GAGvBb,GAAUa,EAEHc,EACP,CAgBMe,CAAaC,EAAOL,GAAMM,EAAmBL,KAE3CZ,EAED,IAAIU,EAAMV,EAAK,EAAGW,EACzB,CAkBD,SAASjB,IACR,IAAIC,EACAiB,EACAF,EACA1C,EACAmB,EACA+B,EACAxD,EACAiD,EACAvB,EAUJ,GALCwB,GAHDjB,EAAQjB,UAAUC,SACJwC,EAAUzC,UAAWiB,EAAM,IAEhCjB,UADRiB,GAAS,GAGDnC,EAGK,QADdkD,EAAO9C,EAAOgD,IAEb,MAAM,IAAI7B,UAAWC,EAAQ,QAAS4B,IAEvC,GAAKjB,GAAS,EACb,OAAO,IAAIe,EAAM,GAGlB,GAAK5B,EAAsBJ,UAAW,IACrC,OAAO+B,EAAYC,EAAMhC,UAAW,GAAKkC,GAG1C,GAAKQ,EAAc1C,UAAW,IAAQ,CAcrC,GAZAiC,GADA3C,EAAMU,UAAW,IACPC,OACL0C,EAAmBrD,GACvBA,EAAM6B,EAAgB7B,EAAK,GAChBsD,EAAkBtD,GAC7BA,EAAM8B,EAAe9B,EAAK,GACfuD,EAAgBvD,GAC3BA,EAAM+B,EAAoB/B,EAAK,GACpBwD,EAAmBZ,KAE9BD,GAAO,GAGK,QADbxB,EAAMsB,EAAYC,EAAMC,EAAKC,IAE5B,OAAOzB,EAER,GAAKlB,EAAiBkB,IAASpB,EAAgBoB,IAASjB,EAAaiB,GAEpE,OADAA,EAAI+B,IAAKlD,GACFmB,EAKR,IAFAzB,EAAM+D,EAAezD,GACrBkD,EAAMQ,EAAevC,GACfC,EAAI,EAAGA,EAAIuB,EAAKvB,IACrB8B,EAAK/B,EAAKC,EAAG1B,EAAKM,EAAKoB,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,QAASN,UAAW,IACjD,CAoGF,CIxUG,IAACiD,EAAiBxD,ICPrBsB,EAAAmC,EAAA,UAAAzD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9bac0b8..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 81d5bb0296358a96e9f1aabc7a27b5bfc9a7a737 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 01:57:40 +0000 Subject: [PATCH 100/103] 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 | 257 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.calloc.js | 265 - benchmark/benchmark.factory.js | 71 - benchmark/benchmark.js | 265 - benchmark/benchmark.length.bool.js | 102 - benchmark/benchmark.length.complex128.js | 102 - benchmark/benchmark.length.complex64.js | 102 - benchmark/benchmark.length.float32.js | 102 - benchmark/benchmark.length.float64.js | 102 - benchmark/benchmark.length.int16.js | 102 - benchmark/benchmark.length.int32.js | 102 - benchmark/benchmark.length.int8.js | 102 - benchmark/benchmark.length.uint16.js | 102 - benchmark/benchmark.length.uint32.js | 102 - benchmark/benchmark.length.uint8.js | 102 - benchmark/benchmark.length.uint8c.js | 102 - benchmark/benchmark.malloc.js | 265 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 53 - dist/index.js.map | 7 - docs/repl.txt | 333 -- docs/types/test.ts | 193 - examples/index.js | 80 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/bytes_per_element.json | 14 - lib/defaults.js | 42 - lib/factory.js | 391 -- lib/index.js | 56 - lib/main.js | 63 - lib/pool.js | 44 - lib/validate.js | 66 - package.json | 104 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 2401 --------- test/test.js | 1935 ------- 65 files changed, 4872 insertions(+), 11531 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.calloc.js delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.bool.js delete mode 100644 benchmark/benchmark.length.complex128.js delete mode 100644 benchmark/benchmark.length.complex64.js delete mode 100644 benchmark/benchmark.length.float32.js delete mode 100644 benchmark/benchmark.length.float64.js delete mode 100644 benchmark/benchmark.length.int16.js delete mode 100644 benchmark/benchmark.length.int32.js delete mode 100644 benchmark/benchmark.length.int8.js delete mode 100644 benchmark/benchmark.length.uint16.js delete mode 100644 benchmark/benchmark.length.uint32.js delete mode 100644 benchmark/benchmark.length.uint8.js delete mode 100644 benchmark/benchmark.length.uint8c.js delete mode 100644 benchmark/benchmark.malloc.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/bytes_per_element.json delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/pool.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0779e8a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index cb23803..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-30T01:42:24.367Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ea35f20..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/array/pool) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be 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 6f7c875..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/array/pool) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 869c4e9..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -481,7 +478,7 @@ console.log( 'nbytes: %d', typedarray.nbytes ); ## 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]. @@ -548,11 +545,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [mdn-arraybuffer]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer -[@stdlib/array/typed-dtypes]: https://github.com/stdlib-js/array-typed-dtypes +[@stdlib/array/typed-dtypes]: https://github.com/stdlib-js/array-typed-dtypes/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/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.calloc.js b/benchmark/benchmark.calloc.js deleted file mode 100644 index 2a04c65..0000000 --- a/benchmark/benchmark.calloc.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var isBooleanArray = require( '@stdlib/assert-is-booleanarray' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':calloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=bool', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'bool' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isBooleanArray( arr ) ) { - b.fail( 'should return a boolean array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 58918bb..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = typedarray.factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:highWaterMark', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'highWaterMark': 0 - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.highWaterMark = i; - f = typedarray.factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 46c6397..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var isBooleanArray = require( '@stdlib/assert-is-booleanarray' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=bool', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'bool' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isBooleanArray( arr ) ) { - b.fail( 'should return a boolean array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.bool.js b/benchmark/benchmark.length.bool.js deleted file mode 100644 index d9ad47b..0000000 --- a/benchmark/benchmark.length.bool.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isBooleanArray = require( '@stdlib/assert-is-booleanarray' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'bool' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isBooleanArray( arr ) ) { - b.fail( 'should return a boolean array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=bool,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=bool,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=bool,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex128.js b/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 12c6668..0000000 --- a/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex64.js b/benchmark/benchmark.length.complex64.js deleted file mode 100644 index ca2b45c..0000000 --- a/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float32.js b/benchmark/benchmark.length.float32.js deleted file mode 100644 index b3b4508..0000000 --- a/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float64.js b/benchmark/benchmark.length.float64.js deleted file mode 100644 index 5f0132d..0000000 --- a/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int16.js b/benchmark/benchmark.length.int16.js deleted file mode 100644 index 9f253cb..0000000 --- a/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int32.js b/benchmark/benchmark.length.int32.js deleted file mode 100644 index f83e795..0000000 --- a/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int8.js b/benchmark/benchmark.length.int8.js deleted file mode 100644 index 5b01174..0000000 --- a/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint16.js b/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 32b0a5d..0000000 --- a/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint32.js b/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 290b90c..0000000 --- a/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8.js b/benchmark/benchmark.length.uint8.js deleted file mode 100644 index ff7d733..0000000 --- a/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8c.js b/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index 8f0d10a..0000000 --- a/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.malloc.js b/benchmark/benchmark.malloc.js deleted file mode 100644 index c85d2fb..0000000 --- a/benchmark/benchmark.malloc.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var isBooleanArray = require( '@stdlib/assert-is-booleanarray' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':malloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=bool', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'bool' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isBooleanArray( arr ) ) { - b.fail( 'should return a boolean array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 612de17..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/array/pool" -%% click B href "https://github.com/stdlib-js/array-pool/tree/main" -%% click C href "https://github.com/stdlib-js/array-pool/tree/production" -%% click D href "https://github.com/stdlib-js/array-pool/tree/esm" -%% click E href "https://github.com/stdlib-js/array-pool/tree/deno" -%% click F href "https://github.com/stdlib-js/array-pool/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/pool -[production-url]: https://github.com/stdlib-js/array-pool/tree/production -[deno-url]: https://github.com/stdlib-js/array-pool/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-pool/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-pool/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-pool/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-pool/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-pool/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 5160b6f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import typedarraypool from '../docs/types/index'; -export = typedarraypool; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 925147b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,53 +0,0 @@ -"use strict";var s=function(n,i){return function(){return i||n((i={exports:{}}).exports,i),i.exports}};var M=s(function(Cr,w){"use strict";function z(){return{highWaterMark:9007199254740992}}w.exports=z});var T=s(function(Or,E){"use strict";var G=require("@stdlib/assert-is-plain-object"),H=require("@stdlib/assert-has-own-property"),J=require("@stdlib/assert-is-nonnegative-integer").isPrimitive,k=require("@stdlib/string-format");function K(n,i){return G(i)?H(i,"highWaterMark")&&(n.highWaterMark=i.highWaterMark,!J(n.highWaterMark))?new TypeError(k("invalid option. `%s` option must be a nonnegative integer. Option: `%s`.","highWaterMark",n.highWaterMark)):null:new TypeError(k("invalid argument. Options argument must be an object. Value: `%s`.",i))}E.exports=K});var B=s(function(Pr,W){"use strict";function Q(n){var i,u;for(i=[],u=0;uv.highWaterMark?null:(e=new fr(r),i+=r,e)}function d(r,e,t){var a;return e===0?new r(0):(a=F(pr(e)*dr[t]),a===null?a:new r(a,0,e))}function o(){var r,e,t,a,l,A,x,c,f;if(r=arguments.length,r&&Z(arguments[r-1])?(r-=1,e=arguments[r]):e=Ar,t=p(e),t===null)throw new TypeError(y("invalid argument. Must provide a recognized data type. Value: `%s`.",e));if(r<=0)return new t(0);if($(arguments[0]))return d(t,arguments[0],e);if(rr(arguments[0])){if(a=arguments[0],c=a.length,nr(a)?a=O(a,0):ir(a)?a=C(a,0):ur(a)?a=P(a,0):tr(e)&&(c/=2),l=d(t,c,e),l===null)return l;if(R(l)||L(l)||N(l))return l.set(a),l;for(x=lr(a),A=sr(l),f=0;f0){for(e=cr(m(r.byteLength)),e=hr(u.length-1,e),t=u[e],a=0;a[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( isBooleanArray( arr ) ) {\n\t\t\t\tarr = reinterpretBoolean( arr, 0 );\n\t\t\t} else if ( isComplexDataType( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) || isBoolArray( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = resolveGetter( arr );\n\t\t\tset = resolveSetter( out );\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else if ( isBoolArray( out ) ) {\n\t\t\t\ttmp = reinterpretBoolean( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nmodule.exports = typedarraypool;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* var typedarraypool = require( '@stdlib/array-pool' );\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,cAAiB,gBAClB,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,eAAgB,IACzCD,EAAK,cAAgBC,EAAQ,cACxB,CAACJ,EAAsBG,EAAK,aAAc,GACvC,IAAI,UAAWF,EAAQ,2EAA4E,gBAAiBE,EAAK,aAAc,CAAE,EAG3I,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cA6BA,SAASC,EAAM,EAAI,CAClB,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAI,EAAE,EAAGA,IACrBD,EAAI,KAAM,CAAC,CAAE,EAEd,OAAOA,CACR,CAKAF,EAAO,QAAUC,IC3CjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,KAAQ,EACR,QAAW,EACX,QAAW,EACX,MAAS,EACT,MAAS,EACT,KAAQ,EACR,OAAU,EACV,OAAU,EACV,MAAS,EACT,OAAU,EACT,UAAa,EACb,WAAc,EAChB,ICbA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,GAAe,QAAS,8BAA+B,EACvDC,GAAmB,QAAS,oCAAqC,EACjEC,GAAgB,QAAS,+BAAgC,EACzDC,GAAoB,QAAS,+DAAgE,EAC7FC,GAAmB,QAAS,kCAAmC,EAC/DC,GAAoB,QAAS,mCAAoC,EACjEC,GAAiB,QAAS,gCAAiC,EAC3DC,EAAc,QAAS,uDAAwD,EAC/EC,GAAsB,QAAS,uDAAwD,EACvFC,EAAQ,QAAS,2BAA4B,EAC7CC,EAAgB,QAAS,4CAA6C,EACtEC,EAAiB,QAAS,6CAA8C,EACxEC,EAAqB,QAAS,0CAA2C,EACzEC,GAAgB,QAAS,mCAAoC,EAC7DC,GAAgB,QAAS,mCAAoC,EAC7DC,GAAiB,QAAS,wBAAyB,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,GAAc,QAAS,sBAAuB,EAC9CC,GAAO,QAAS,gCAAiC,EACjDC,GAAQ,QAAS,iCAAkC,EACnDC,GAAQ,QAAS,iCAAkC,EACnDC,EAAO,QAAS,gCAAiC,EACjDC,GAAM,QAAS,+BAAgC,EAC/CC,GAAW,IACXC,GAAW,IACXC,GAAa,IACbC,GAAoB,IAKpBC,GAAgBZ,GAAe,IAAK,gBAAiB,EACrDa,GAAiBnB,EAAO,WAAY,EACpCoB,GAAkBpB,EAAO,YAAa,EACtCqB,GAAerB,EAAO,MAAO,EAYjC,SAASsB,EAAgBC,EAAM,CAC9B,OAASA,aAAeJ,EACzB,CASA,SAASK,EAAiBD,EAAM,CAC/B,OAASA,aAAeH,EACzB,CASA,SAASK,EAAaF,EAAM,CAC3B,OAASA,aAAeF,EACzB,CA6BA,SAASK,GAASC,EAAU,CAC3B,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,EAAOhB,GAAS,EACX,UAAU,SACdiB,EAAMhB,GAAUe,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAAF,EAAOb,GAAYP,GAAMG,EAAMkB,EAAK,aAAc,CAAE,CAAE,EACtDF,EAAS,EAET9B,EAAakC,EAAQ,SAAUA,CAAO,EACtClC,EAAakC,EAAQ,SAAUC,CAAO,EACtCnC,EAAakC,EAAQ,OAAQE,CAAK,EAClCpC,EAAakC,EAAQ,QAASG,CAAM,EACpCrC,EAAakC,EAAQ,gBAAiBF,EAAK,aAAc,EACzD/B,GAAqBiC,EAAQ,SAAUI,CAAS,EAEzCJ,EAQP,SAASI,GAAW,CACnB,OAAOR,CACR,CASA,SAASS,EAAaC,EAAI,CACzB,IAAIC,EACAC,EAMJ,OAHAA,EAAI5B,EAAM0B,CAAE,EAGPE,EAAIX,EAAK,QAAUA,EAAMW,CAAE,EAAE,OAC1BX,EAAMW,CAAE,EAAE,IAAI,EAGjBZ,EAAOU,EAAIR,EAAK,cACb,MAERS,EAAM,IAAI/B,GAAa8B,CAAE,EAGzBV,GAAUU,EAEHC,EACR,CAWA,SAASE,EAAYC,EAAMC,EAAKC,EAAQ,CACvC,IAAIL,EACJ,OAAKI,IAAQ,EACL,IAAID,EAAM,CAAE,GAEpBH,EAAMF,EAAa1B,GAAOgC,CAAI,EAAE1B,GAAmB2B,CAAM,CAAE,EACtDL,IAAQ,KACLA,EAED,IAAIG,EAAMH,EAAK,EAAGI,CAAI,EAC9B,CAkBA,SAASX,GAAS,CACjB,IAAIa,EACAD,EACAF,EACAnB,EACAuB,EACAC,EACAC,EACAL,EACAH,EAUJ,GARAK,EAAQ,UAAU,OACbA,GAASxD,EAAU,UAAWwD,EAAM,CAAE,CAAE,GAC5CA,GAAS,EACTD,EAAQ,UAAWC,CAAM,GAEzBD,EAAQ1B,GAETwB,EAAO1C,EAAO4C,CAAM,EACfF,IAAS,KACb,MAAM,IAAI,UAAWnC,EAAQ,sEAAuEqC,CAAM,CAAE,EAE7G,GAAKC,GAAS,EACb,OAAO,IAAIH,EAAM,CAAE,EAGpB,GAAKpD,EAAsB,UAAW,CAAE,CAAE,EACzC,OAAOmD,EAAYC,EAAM,UAAW,CAAE,EAAGE,CAAM,EAGhD,GAAKrD,GAAc,UAAW,CAAE,CAAE,EAAI,CAcrC,GAbAgC,EAAM,UAAW,CAAE,EACnBoB,EAAMpB,EAAI,OACL3B,GAAmB2B,CAAI,EAC3BA,EAAMrB,EAAgBqB,EAAK,CAAE,EAClB5B,GAAkB4B,CAAI,EACjCA,EAAMtB,EAAesB,EAAK,CAAE,EACjB1B,GAAgB0B,CAAI,EAC/BA,EAAMpB,EAAoBoB,EAAK,CAAE,EACtB7B,GAAmBkD,CAAM,IAEpCD,GAAO,GAERG,EAAML,EAAYC,EAAMC,EAAKC,CAAM,EAC9BE,IAAQ,KACZ,OAAOA,EAER,GAAKtB,EAAiBsB,CAAI,GAAKxB,EAAgBwB,CAAI,GAAKrB,EAAaqB,CAAI,EACxE,OAAAA,EAAI,IAAKvB,CAAI,EACNuB,EAKR,IAFAE,EAAM5C,GAAemB,CAAI,EACzBwB,EAAM1C,GAAeyC,CAAI,EACnBN,EAAI,EAAGA,EAAIG,EAAKH,IACrBO,EAAKD,EAAKN,EAAGQ,EAAKzB,EAAKiB,CAAE,CAAE,EAE5B,OAAOM,CACR,CACA,MAAM,IAAI,UAAWvC,EAAQ,wGAAyG,UAAW,CAAE,CAAE,CAAE,CACxJ,CAgBA,SAAS0B,GAAS,CACjB,IAAIY,EACAC,EACAG,EACAT,EAUJ,GARAK,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAMd,EAAO,EACFa,IAAU,EACrBC,EAAMd,EAAQ,UAAW,CAAE,CAAE,EAE7Bc,EAAMd,EAAQ,UAAW,CAAE,EAAG,UAAW,CAAE,CAAE,EAEzCc,IAAQ,KAWZ,IATKtB,EAAiBsB,CAAI,EACzBG,EAAM/C,EAAgB4C,EAAK,CAAE,EAClBxB,EAAgBwB,CAAI,EAC/BG,EAAMhD,EAAe6C,EAAK,CAAE,EACjBrB,EAAaqB,CAAI,EAC5BG,EAAM9C,EAAoB2C,EAAK,CAAE,EAEjCG,EAAMH,EAEDN,EAAI,EAAGA,EAAIS,EAAI,OAAQT,IAC5BS,EAAKT,CAAE,EAAI,EAGb,OAAOM,CACR,CAcA,SAASZ,EAAMK,EAAM,CACpB,IAAID,EACAY,EACAV,EACJ,GAAKhD,GAAkB+C,CAAI,GAAKA,EAAI,OACnCA,EAAMA,EAAI,eACC,CAAC9C,GAAe8C,CAAI,EAC/B,MAAM,IAAI,UAAWhC,EAAQ,4EAA6EgC,CAAI,CAAE,EAEjH,GAAKA,EAAI,WAAa,EAAI,CAQzB,IAPAD,EAAI5B,GAAOE,EAAM2B,EAAI,UAAW,CAAE,EAGlCD,EAAIzB,GAAKgB,EAAK,OAAO,EAAGS,CAAE,EAG1BY,EAAIrB,EAAMS,CAAE,EACNE,EAAI,EAAGA,EAAIU,EAAE,OAAQV,IAC1B,GAAKU,EAAGV,CAAE,IAAMD,EACf,MAAO,GAITW,EAAE,KAAMX,CAAI,CACb,CACA,MAAO,EACR,CAOA,SAASJ,GAAQ,CAChB,IAAIK,EACJ,IAAMA,EAAI,EAAGA,EAAIX,EAAK,OAAQW,IAC7BX,EAAMW,CAAE,EAAE,OAAS,EAEpBZ,EAAS,CACV,CACD,CAKAxC,EAAO,QAAUsC,KCtYjB,IAAAyB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAU,IAmCVC,GAAiBD,GAAQ,EAK7BD,EAAO,QAAUE,KCnBjB,IAAIC,GAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,GAAU,IAKdF,GAAaC,EAAM,UAAWC,EAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isNonNegativeInteger", "format", "validate", "opts", "options", "require_pool", "__commonJSMin", "exports", "module", "pool", "out", "i", "require_bytes_per_element", "__commonJSMin", "exports", "module", "require_factory", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isCollection", "isTypedArrayLike", "isArrayBuffer", "isComplexDataType", "isComplex64Array", "isComplex128Array", "isBooleanArray", "setReadOnly", "setReadOnlyAccessor", "ctors", "reinterpret64", "reinterpret128", "reinterpretBoolean", "resolveGetter", "resolveSetter", "ARRAY_DEFAULTS", "format", "ArrayBuffer", "ceil", "floor", "ceil2", "log2", "min", "defaults", "validate", "createPool", "BYTES_PER_ELEMENT", "DEFAULT_DTYPE", "Complex64Array", "Complex128Array", "BooleanArray", "isCmplx64Array", "arr", "isCmplx128Array", "isBoolArray", "factory", "options", "nbytes", "pool", "opts", "err", "malloc", "calloc", "free", "clear", "getBytes", "arraybuffer", "n", "buf", "i", "typedarray", "ctor", "len", "dtype", "nargs", "out", "set", "get", "tmp", "p", "require_main", "__commonJSMin", "exports", "module", "factory", "typedarraypool", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a2727d6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,333 +0,0 @@ - -{{alias}}( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - Memory is **uninitialized**, which means that the contents of a returned - typed array may contain sensitive contents. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}() - [] - > arr = {{alias}}( 'float32' ) - [] - - -{{alias}}( length[, dtype] ) - Returns an uninitialized typed array having a specified length from a typed - array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > arr = {{alias}}( 5, 'int32' ) - - - -{{alias}}( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - This method shares the same security vulnerabilities mentioned above. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc() - - > arr = {{alias}}.malloc( 'float32' ) - - - -{{alias}}.malloc( length[, dtype] ) - Returns a typed array having a specified length from a typed array memory - pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc( 5 ) - - > arr = {{alias}}.malloc( 5, 'int32' ) - - - -{{alias}}.malloc( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}.malloc( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.calloc( [dtype] ) - Returns a zero-initialized typed array from a typed array memory pool. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc() - [] - > arr = {{alias}}.calloc( 'float32' ) - [] - - -{{alias}}.calloc( length[, dtype] ) - Returns a zero-initialized typed array having a specified length from a - typed array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}.calloc( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}.free( buf ) - Frees a typed array or typed array buffer for use in a future allocation. - - Parameters - ---------- - buf: TypedArray|ArrayBuffer - Typed array or typed array buffer to free. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - - -{{alias}}.clear() - Clears the typed array pool allowing garbage collection of previously - allocated (and currently free) array buffers. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - > {{alias}}.clear(); - - -{{alias}}.highWaterMark - Read-only property returning the pool's high water mark. - - Once a high water mark is reached, typed array allocation fails. - - Examples - -------- - > {{alias}}.highWaterMark - - - -{{alias}}.nbytes - Read-only property returning the total number of allocated bytes. - - The returned value is the total accumulated value. Hence, anytime a pool - must allocate a new array buffer (i.e., more memory), the pool increments - this value. - - The only time this value is decremented is when a pool is cleared. - - This behavior means that, while allocated buffers which are never freed may, - in fact, be garbage collected, they continue to count against the high water - mark limit. - - Accordingly, you should *always* free allocated buffers in order to prevent - the pool from believing that non-freed buffers are continually in use. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.nbytes - - - -{{alias}}.factory( [options] ) - Creates a typed array pool. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.highWaterMark: integer (optional) - Maximum total memory (in bytes) which can be allocated. - - Returns - ------- - fcn: Function - Function for creating typed arrays from a typed array memory pool. - - Examples - -------- - > var pool = {{alias}}.factory(); - > var arr1 = pool( 3, 'float64' ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 4336c42..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,193 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-empty */ -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import typedarraypool = require( './index' ); - - -// TESTS // - -// The function returns a typed array or null... -{ - typedarraypool(); // $ExpectType TypedArrayOrNull - typedarraypool( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the function is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool( true ); // $ExpectError - typedarraypool( false ); // $ExpectError - typedarraypool( null ); // $ExpectError - typedarraypool( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized data type... -{ - typedarraypool( 4, true ); // $ExpectError - typedarraypool( 4, false ); // $ExpectError - typedarraypool( 4, null ); // $ExpectError - typedarraypool( 4, 'abc' ); // $ExpectError - typedarraypool( 4, 123 ); // $ExpectError - typedarraypool( 4, [] ); // $ExpectError - typedarraypool( 4, {} ); // $ExpectError - typedarraypool( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an incorrect number of arguments... -{ - typedarraypool( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `malloc` method which returns a typed array or null... -{ - typedarraypool.malloc(); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.malloc( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `malloc` method is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool.malloc( true ); // $ExpectError - typedarraypool.malloc( false ); // $ExpectError - typedarraypool.malloc( null ); // $ExpectError - typedarraypool.malloc( {} ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.malloc( 4, true ); // $ExpectError - typedarraypool.malloc( 4, false ); // $ExpectError - typedarraypool.malloc( 4, null ); // $ExpectError - typedarraypool.malloc( 4, 'abc' ); // $ExpectError - typedarraypool.malloc( 4, 123 ); // $ExpectError - typedarraypool.malloc( 4, [] ); // $ExpectError - typedarraypool.malloc( 4, {} ); // $ExpectError - typedarraypool.malloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided an incorrect number of arguments... -{ - typedarraypool.malloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `calloc` method which returns a typed array or null... -{ - typedarraypool.calloc(); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `calloc` method is provided a first argument which is not a number... -{ - typedarraypool.calloc( 'abc' ); // $ExpectError - typedarraypool.calloc( true ); // $ExpectError - typedarraypool.calloc( false ); // $ExpectError - typedarraypool.calloc( null ); // $ExpectError - typedarraypool.calloc( {} ); // $ExpectError - typedarraypool.calloc( [] ); // $ExpectError - typedarraypool.calloc( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.calloc( 4, true ); // $ExpectError - typedarraypool.calloc( 4, false ); // $ExpectError - typedarraypool.calloc( 4, null ); // $ExpectError - typedarraypool.calloc( 4, 'abc' ); // $ExpectError - typedarraypool.calloc( 4, 123 ); // $ExpectError - typedarraypool.calloc( 4, [] ); // $ExpectError - typedarraypool.calloc( 4, {} ); // $ExpectError - typedarraypool.calloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided an incorrect number of arguments... -{ - typedarraypool.calloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `factory` method which returns a typed array pool.. -{ - typedarraypool.factory(); // $ExpectType Pool - typedarraypool.factory( { 'highWaterMark': 556 } ); // $ExpectType Pool -} - -// The compiler throws an error if the `factory` method is provided a `highWaterMark` option which is not a number... -{ - typedarraypool.factory( { 'highWaterMark': true } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': false } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': 'abc' } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': null } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': [] } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': {} } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an incorrect number of arguments... -{ - typedarraypool.factory( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` method which returns void... -{ - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.free( arr ); // $ExpectType void -} - -// The compiler throws an error if the `free` method is provided a first argument which is neither a typed array nor array buffer... -{ - typedarraypool.free( true ); // $ExpectError - typedarraypool.free( false ); // $ExpectError - typedarraypool.free( 123 ); // $ExpectError - typedarraypool.free( 'abc' ); // $ExpectError - typedarraypool.free( null ); // $ExpectError - typedarraypool.free( {} ); // $ExpectError - typedarraypool.free( ( x: number ): number => x ); // $ExpectError -} - -// Attached to the main export is a `clear` method which returns void... -{ - typedarraypool.clear(); // $ExpectType void -} - -// The compiler throws an error if the `clear` method is provided arguments... -{ - typedarraypool.clear( {} ); // $ExpectError - typedarraypool.clear( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `highWaterMark` property... -{ - typedarraypool.highWaterMark; // $ExpectType number -} - -// Attached to the main export is a `nbytes` property... -{ - typedarraypool.nbytes; // $ExpectType number -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 24a7846..0000000 --- a/examples/index.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 randu = require( '@stdlib/random-base-randu' ); -var typedarraypool = require( './../lib' ); - -// Create a typed array pool which can allocate at most 1GB: -var typedarray = typedarraypool.factory({ - 'highWaterMark': 1e9 -}); - -// Inspect the pool: -console.log( 'Max bytes: %d', typedarray.highWaterMark ); -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Allocate an array for storing double-precision floating-point numbers: -var arr1 = typedarray( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Fill the array... -var i; -for ( i = 0; i < arr1.length; i++ ) { - arr1[ i ] = randu(); -} - -// Inspect array contents: -console.log( arr1 ); - -// Free the array: -typedarray.free( arr1 ); - -// Allocate another array similar to the previous one: -var arr2 = typedarray( 5, 'float64' ); -// returns - -// Check that we have been returned a new typed array view: -console.log( arr2 === arr1 ); -// => false - -// Inspect array contents: -console.log( arr2 ); - -// Free the array: -typedarray.free( arr2 ); - -// Allocate an initialized array: -var arr3 = typedarray.calloc( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect array contents: -console.log( arr3 ); - -// Free the array: -typedarray.free( arr3 ); - -// Clear the pool: -typedarray.clear(); - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 4dc8736..8298bf3 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike, RealOrComplexTypedArray, BooleanArray, NumericDataType as DataType } from '@stdlib/types/array'; import ArrayBuffer = require( '@stdlib/array-buffer' ); diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..0fb5914 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-booleanarray@v0.0.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.3.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.2.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.2-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-setter@v0.2.2-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/array-defaults@v0.3.0-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.2.2-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.2.3-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.3.0-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.3.0-esm/index.mjs";import M from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.2.3-esm/index.mjs";import W from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";var H={bool:1,float64:8,float32:4,int16:2,int32:4,int8:1,uint16:2,uint32:4,uint8:1,uint8c:1,complex64:8,complex128:16},T=g.get("dtypes.default"),L=h("complex64"),P=h("complex128"),V=h("bool");function Y(e){return e instanceof L}function q(e){return e instanceof P}function z(e){return e instanceof V}function A(g){var L,P,V,A;if(V={highWaterMark:9007199254740992},arguments.length&&(A=function(e,t){return W(t)?E(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(u("01H2t","highWaterMark",e.highWaterMark)):null:new TypeError(u("01H2V",t))}(V,g),A))throw A;return P=function(e){var t,r;for(t=[],r=0;r0){for(t=y(k(e.byteLength)),t=M(P.length-1,t),r=P[t],s=0;sV.highWaterMark?null:(t=new b(e),L+=e,t)}(w(t)*H[r]))?s:new e(s,0,t)}function C(){var e,i,n,a,g,b,x,y,w;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:T,null===(n=h(i)))throw new TypeError(u("01H2Y",i));if(e<=0)return new n(0);if(r(arguments[0]))return B(n,arguments[0],i);if(s(arguments[0])){if(y=(a=arguments[0]).length,d(a)?a=j(a,0):m(a)?a=p(a,0):l(a)?a=f(a,0):o(i)&&(y/=2),null===(g=B(n,y,i)))return g;if(q(g)||Y(g)||z(g))return g.set(a),g;for(x=c(a),b=v(g),w=0;w[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '01H2Y', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( isBooleanArray( arr ) ) {\n\t\t\t\tarr = reinterpretBoolean( arr, 0 );\n\t\t\t} else if ( isComplexDataType( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) || isBoolArray( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = resolveGetter( arr );\n\t\t\tset = resolveSetter( out );\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '01H2r', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else if ( isBoolArray( out ) ) {\n\t\t\t\ttmp = reinterpretBoolean( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( '01H2s', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'highWaterMark': 1024\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '01H2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'highWaterMark' ) ) {\n\t\topts.highWaterMark = options.highWaterMark;\n\t\tif ( !isNonNegativeInteger( opts.highWaterMark ) ) {\n\t\t\treturn new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Initializes a cache for pooled typed array buffers.\n*\n* @private\n* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size\n* @returns {ArrayArray} initialized cache\n*/\nfunction pool( n ) {\n\tvar out;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < n+1; i++ ) {\n\t\tout.push( [] );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default pool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DEFAULT_DTYPE","ARRAY_DEFAULTS","get","Complex64Array","ctors","Complex128Array","BooleanArray","isCmplx64Array","arr","isCmplx128Array","isBoolArray","factory","options","nbytes","pool","opts","err","highWaterMark","arguments","length","isObject","hasOwnProp","isNonNegativeInteger","TypeError","format","validate","n","out","i","push","createPool","ceil","log2","setReadOnly","malloc","nargs","tmp","reinterpret128","reinterpret64","reinterpretBoolean","buf","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","setReadOnlyAccessor","typedarray","ctor","len","dtype","pop","ArrayBuffer","arraybuffer","ceil2","BYTES_PER_ELEMENT","set","isString","isCollection","isComplex128Array","isComplex64Array","isBooleanArray","isComplexDataType","resolveGetter","resolveSetter","typedarraypool","main"],"mappings":";;wzFAuDIA,EAAgBC,EAAeC,IAAK,kBACpCC,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cACzBE,EAAeF,EAAO,QAY1B,SAASG,EAAgBC,GACxB,OAASA,aAAeL,CACzB,CASA,SAASM,EAAiBD,GACzB,OAASA,aAAeH,CACzB,CASA,SAASK,EAAaF,GACrB,OAASA,aAAeF,CACzB,CA6BA,SAASK,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,EChGO,CACNE,cAAiB,kBDgGbC,UAAUC,SACdH,EElFF,SAAmBD,EAAMH,GACxB,OAAMQ,EAAUR,GAGXS,EAAYT,EAAS,mBACzBG,EAAKE,cAAgBL,EAAQK,eACvBK,EAAsBP,EAAKE,gBACzB,IAAIM,UAAWC,EAAQ,QAAS,gBAAiBT,EAAKE,gBAGxD,KARC,IAAIM,UAAWC,EAAQ,QAASZ,GASzC,CFuEQa,CAAUV,EAAMH,GACjBI,GACJ,MAAMA,EAaR,OAVAF,EG3GD,SAAeY,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,CHkGQG,CAAYC,EAAMC,EAAMjB,EAAKE,iBACpCJ,EAAS,EAEToB,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,UAiKrB,WACC,IAAIC,EACAR,EACAS,EACAR,EAEJO,EAAQjB,UAAUC,OAEjBQ,EADc,IAAVQ,EACED,IACe,IAAVC,EACLD,EAAQhB,UAAW,IAEnBgB,EAAQhB,UAAW,GAAKA,UAAW,IAE1C,GAAa,OAARS,EAWJ,IARCS,EADI3B,EAAiBkB,GACfU,EAAgBV,EAAK,GAChBpB,EAAgBoB,GACrBW,EAAeX,EAAK,GACfjB,EAAaiB,GAClBY,EAAoBZ,EAAK,GAEzBA,EAEDC,EAAI,EAAGA,EAAIQ,EAAIjB,OAAQS,IAC5BQ,EAAKR,GAAM,EAGb,OAAOD,CACP,IA9LDM,EAAaC,EAAQ,QA4MrB,SAAeM,GACd,IAAId,EACAe,EACAb,EACJ,GAAKc,EAAkBF,IAASA,EAAIG,OACnCH,EAAMA,EAAIG,YACJ,IAAMC,EAAeJ,GAC3B,MAAM,IAAIjB,UAAWC,EAAQ,QAASgB,IAEvC,GAAKA,EAAIK,WAAa,EAAI,CAQzB,IAPAnB,EAAIoB,EAAOd,EAAMQ,EAAIK,aAGrBnB,EAAIqB,EAAKjC,EAAKK,OAAO,EAAGO,GAGxBe,EAAI3B,EAAMY,GACJE,EAAI,EAAGA,EAAIa,EAAEtB,OAAQS,IAC1B,GAAKa,EAAGb,KAAQY,EACf,OAAO,EAITC,EAAEZ,KAAMW,EACR,CACD,OAAO,CACP,IArODP,EAAaC,EAAQ,SA4OrB,WACC,IAAIN,EACJ,IAAMA,EAAI,EAAGA,EAAId,EAAKK,OAAQS,IAC7Bd,EAAMc,GAAIT,OAAS,EAEpBN,EAAS,CACT,IAjPDoB,EAAaC,EAAQ,gBAAiBnB,EAAKE,eAC3C+B,EAAqBd,EAAQ,UAU7B,WACC,OAAOrB,CACP,IAVMqB,EAmDP,SAASe,EAAYC,EAAMC,EAAKC,GAC/B,IAAIZ,EACJ,OAAa,IAARW,EACG,IAAID,EAAM,GAGL,QADbV,EArCD,SAAsBd,GACrB,IAAIc,EACAZ,EAMJ,OAHAA,EAAII,EAAMN,IAGDZ,EAAKK,QAAUL,EAAMc,GAAIT,OAC1BL,EAAMc,GAAIyB,MAGbxC,EAAOa,EAAIX,EAAKE,cACb,MAERuB,EAAM,IAAIc,EAAa5B,GAGvBb,GAAUa,EAEHc,EACP,CAgBMe,CAAaC,EAAOL,GAAMM,EAAmBL,KAE3CZ,EAED,IAAIU,EAAMV,EAAK,EAAGW,EACzB,CAkBD,SAASjB,IACR,IAAIC,EACAiB,EACAF,EACA1C,EACAmB,EACA+B,EACAxD,EACAiD,EACAvB,EAUJ,GALCwB,GAHDjB,EAAQjB,UAAUC,SACJwC,EAAUzC,UAAWiB,EAAM,IAEhCjB,UADRiB,GAAS,GAGDnC,EAGK,QADdkD,EAAO9C,EAAOgD,IAEb,MAAM,IAAI7B,UAAWC,EAAQ,QAAS4B,IAEvC,GAAKjB,GAAS,EACb,OAAO,IAAIe,EAAM,GAGlB,GAAK5B,EAAsBJ,UAAW,IACrC,OAAO+B,EAAYC,EAAMhC,UAAW,GAAKkC,GAG1C,GAAKQ,EAAc1C,UAAW,IAAQ,CAcrC,GAZAiC,GADA3C,EAAMU,UAAW,IACPC,OACL0C,EAAmBrD,GACvBA,EAAM6B,EAAgB7B,EAAK,GAChBsD,EAAkBtD,GAC7BA,EAAM8B,EAAe9B,EAAK,GACfuD,EAAgBvD,GAC3BA,EAAM+B,EAAoB/B,EAAK,GACpBwD,EAAmBZ,KAE9BD,GAAO,GAGK,QADbxB,EAAMsB,EAAYC,EAAMC,EAAKC,IAE5B,OAAOzB,EAER,GAAKlB,EAAiBkB,IAASpB,EAAgBoB,IAASjB,EAAaiB,GAEpE,OADAA,EAAI+B,IAAKlD,GACFmB,EAKR,IAFAzB,EAAM+D,EAAezD,GACrBkD,EAAMQ,EAAevC,GACfC,EAAI,EAAGA,EAAIuB,EAAKvB,IACrB8B,EAAK/B,EAAKC,EAAG1B,EAAKM,EAAKoB,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,QAASN,UAAW,IACjD,CAoGF,CIxUG,IAACiD,EAAiBxD,ICPrBsB,EAAAmC,EAAA,UAAAzD"} \ No newline at end of file diff --git a/lib/bytes_per_element.json b/lib/bytes_per_element.json deleted file mode 100644 index 30f02fc..0000000 --- a/lib/bytes_per_element.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "bool": 1, - "float64": 8, - "float32": 4, - "int16": 2, - "int32": 4, - "int8": 1, - "uint16": 2, - "uint32": 4, - "uint8": 1, - "uint8c": 1, - "complex64": 8, - "complex128": 16 -} diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index a421711..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +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'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'highWaterMark': 9007199254740992 - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 7f297ce..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,391 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' ); -var isComplex64Array = require( '@stdlib/assert-is-complex64array' ); -var isComplex128Array = require( '@stdlib/assert-is-complex128array' ); -var isBooleanArray = require( '@stdlib/assert-is-booleanarray' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var ctors = require( '@stdlib/array-typed-ctors' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var resolveSetter = require( '@stdlib/array-base-resolve-setter' ); -var ARRAY_DEFAULTS = require( '@stdlib/array-defaults' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil = require( '@stdlib/math-base-special-ceil' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); -var log2 = require( '@stdlib/math-base-special-log2' ); -var min = require( '@stdlib/math-base-special-min' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var createPool = require( './pool.js' ); -var BYTES_PER_ELEMENT = require( './bytes_per_element.json' ); - - -// VARIABLES // - -var DEFAULT_DTYPE = ARRAY_DEFAULTS.get( 'dtypes.default' ); -var Complex64Array = ctors( 'complex64' ); -var Complex128Array = ctors( 'complex128' ); -var BooleanArray = ctors( 'bool' ); - - -// FUNCTIONS // - -/** -* Tests whether an array is a single-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a single-precision complex floating-point number array -*/ -function isCmplx64Array( arr ) { - return ( arr instanceof Complex64Array ); -} - -/** -* Tests whether an array is a double-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a double-precision complex floating-point number array -*/ -function isCmplx128Array( arr ) { - return ( arr instanceof Complex128Array ); -} - -/** -* Tests whether an array is a boolean array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a boolean array -*/ -function isBoolArray( arr ) { - return ( arr instanceof BooleanArray ); -} - - -// MAIN // - -/** -* Creates a typed array pool. -* -* @param {Options} [options] - pool options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} allocator -* -* @example -* var typedarraypool = factory(); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -function factory( options ) { - var nbytes; - var pool; - var opts; - var err; - - opts = defaults(); - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - pool = createPool( ceil( log2( opts.highWaterMark ) ) ); - nbytes = 0; - - setReadOnly( malloc, 'malloc', malloc ); // circular reference - setReadOnly( malloc, 'calloc', calloc ); - setReadOnly( malloc, 'free', free ); - setReadOnly( malloc, 'clear', clear ); - setReadOnly( malloc, 'highWaterMark', opts.highWaterMark ); - setReadOnlyAccessor( malloc, 'nbytes', getBytes ); - - return malloc; - - /** - * Returns the number of allocated bytes. - * - * @private - * @returns {NonNegativeInteger} number of allocated bytes - */ - function getBytes() { - return nbytes; - } - - /** - * Returns an array buffer. - * - * @private - * @param {NonNegativeInteger} n - number of bytes - * @returns {(ArrayBuffer|null)} array buffer or null - */ - function arraybuffer( n ) { - var buf; - var i; - - // Convert the number of bytes to an index in our pool table: - i = log2( n ); - - // If we already have an available array buffer, use it... - if ( i < pool.length && pool[ i ].length ) { - return pool[ i ].pop(); - } - // Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate... - if ( nbytes+n > opts.highWaterMark ) { - return null; - } - buf = new ArrayBuffer( n ); - - // Update the running counter of allocated bytes: - nbytes += n; - - return buf; - } - - /** - * Returns a typed array. - * - * @private - * @param {Function} ctor - typed array constructor - * @param {NonNegativeInteger} len - view length - * @param {string} dtype - data type - * @returns {(TypedArray|null)} typed array or null - */ - function typedarray( ctor, len, dtype ) { - var buf; - if ( len === 0 ) { - return new ctor( 0 ); - } - buf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] ); - if ( buf === null ) { - return buf; - } - return new ctor( buf, 0, len ); - } - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length or an array-like object - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function malloc() { - var nargs; - var dtype; - var ctor; - var arr; - var out; - var set; - var get; - var len; - var i; - - nargs = arguments.length; - if ( nargs && isString( arguments[ nargs-1 ] ) ) { - nargs -= 1; - dtype = arguments[ nargs ]; - } else { - dtype = DEFAULT_DTYPE; - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( '01H2Y', dtype ) ); - } - if ( nargs <= 0 ) { - return new ctor( 0 ); - } - // Check if provided a typed array length... - if ( isNonNegativeInteger( arguments[ 0 ] ) ) { - return typedarray( ctor, arguments[ 0 ], dtype ); - } - // Check if provided an array-like object containing data elements... - if ( isCollection( arguments[ 0 ] ) ) { - arr = arguments[ 0 ]; - len = arr.length; - if ( isComplex128Array( arr ) ) { - arr = reinterpret128( arr, 0 ); - } else if ( isComplex64Array( arr ) ) { - arr = reinterpret64( arr, 0 ); - } else if ( isBooleanArray( arr ) ) { - arr = reinterpretBoolean( arr, 0 ); - } else if ( isComplexDataType( dtype ) ) { - // Assume we've been provided an array of interleaved real and imaginary components... - len /= 2; - } - out = typedarray( ctor, len, dtype ); - if ( out === null ) { - return out; - } - if ( isCmplx128Array( out ) || isCmplx64Array( out ) || isBoolArray( out ) ) { - out.set( arr ); - return out; - } - // Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other "unsafe" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things... - get = resolveGetter( arr ); - set = resolveSetter( out ); - for ( i = 0; i < len; i++ ) { - set( out, i, get( arr, i ) ); - } - return out; - } - throw new TypeError( format( '01H2r', arguments[ 0 ] ) ); - } - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {NonNegativeInteger} [len=0] - array length - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function calloc() { - var nargs; - var out; - var tmp; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - out = malloc(); - } else if ( nargs === 1 ) { - out = malloc( arguments[ 0 ] ); - } else { - out = malloc( arguments[ 0 ], arguments[ 1 ] ); - } - if ( out !== null ) { - // Initialize the memory... - if ( isCmplx128Array( out ) ) { - tmp = reinterpret128( out, 0 ); - } else if ( isCmplx64Array( out ) ) { - tmp = reinterpret64( out, 0 ); - } else if ( isBoolArray( out ) ) { - tmp = reinterpretBoolean( out, 0 ); - } else { - tmp = out; - } - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = 0.0; - } - } - return out; - } - - /** - * Frees a typed array or typed array buffer. - * - * ## Notes - * - * - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., "freeing" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool. - * - * @private - * @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free - * @throws {TypeError} must provide a typed array or typed array buffer - * @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed - */ - function free( buf ) { - var n; - var p; - var i; - if ( isTypedArrayLike( buf ) && buf.buffer ) { - buf = buf.buffer; - } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( '01H2s', buf ) ); - } - if ( buf.byteLength > 0 ) { - n = floor( log2( buf.byteLength ) ); - - // Prohibit "freeing" array buffers which would potentially allow users to circumvent high water mark limits: - n = min( pool.length-1, n ); - - // Ensure that we do not attempt to free the same buffer more than once... - p = pool[ n ]; - for ( i = 0; i < p.length; i++ ) { - if ( p[ i ] === buf ) { - return false; - } - } - // Add the buffer to our pool of free buffers: - p.push( buf ); - } - return true; - } - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @private - */ - function clear() { - var i; - for ( i = 0; i < pool.length; i++ ) { - pool[ i ].length = 0; - } - nbytes = 0; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6c12a4e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Typed array pool. -* -* @module @stdlib/array-pool -* -* @example -* var typedarraypool = require( '@stdlib/array-pool' ); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8f69ee3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,63 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @name typedarraypool -* @type {Function} -* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a valid array length or an array-like object -* @throws {TypeError} must provide a recognized data type -* @returns {(TypedArray|null)} typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -var typedarraypool = factory(); - - -// EXPORTS // - -module.exports = typedarraypool; diff --git a/lib/pool.js b/lib/pool.js deleted file mode 100644 index 5abd287..0000000 --- a/lib/pool.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Initializes a cache for pooled typed array buffers. -* -* @private -* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size -* @returns {ArrayArray} initialized cache -*/ -function pool( n ) { - var out; - var i; - - out = []; - for ( i = 0; i < n+1; i++ ) { - out.push( [] ); - } - return out; -} - - -// EXPORTS // - -module.exports = pool; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index da746bb..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'highWaterMark': 1024 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '01H2V', options ) ); - } - if ( hasOwnProp( options, 'highWaterMark' ) ) { - opts.highWaterMark = options.highWaterMark; - if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 2945498..ce31461 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Typed array pool.", "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,83 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-is-complex-floating-point-data-type": "^0.2.1", - "@stdlib/array-base-resolve-getter": "^0.2.2", - "@stdlib/array-base-resolve-setter": "^0.2.2", - "@stdlib/array-buffer": "^0.2.2", - "@stdlib/array-defaults": "^0.3.0", - "@stdlib/array-typed-ctors": "^0.3.0", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-arraybuffer": "^0.2.2", - "@stdlib/assert-is-booleanarray": "^0.0.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-complex128array": "^0.2.2", - "@stdlib/assert-is-complex64array": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-string": "^0.2.2", - "@stdlib/assert-is-typed-array-like": "^0.2.2", - "@stdlib/math-base-special-ceil": "^0.2.2", - "@stdlib/math-base-special-ceil2": "^0.3.0", - "@stdlib/math-base-special-floor": "^0.2.3", - "@stdlib/math-base-special-log2": "^0.3.0", - "@stdlib/math-base-special-min": "^0.2.3", - "@stdlib/strided-base-reinterpret-boolean": "^0.0.2", - "@stdlib/strided-base-reinterpret-complex128": "^0.2.2", - "@stdlib/strided-base-reinterpret-complex64": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-bool": "^0.1.0", - "@stdlib/array-complex128": "^0.3.0", - "@stdlib/array-complex64": "^0.3.0", - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int16": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint16": "^0.2.2", - "@stdlib/array-uint32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/array-uint8c": "^0.2.2", - "@stdlib/assert-instance-of": "^0.2.2", - "@stdlib/assert-is-complex-typed-array": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-typed-array": "^0.2.2", - "@stdlib/boolean-ctor": "^0.2.2", - "@stdlib/complex-float32-ctor": "^0.0.2", - "@stdlib/complex-float32-imag": "^0.1.1", - "@stdlib/complex-float32-real": "^0.1.1", - "@stdlib/complex-float64-ctor": "^0.0.3", - "@stdlib/complex-float64-imag": "^0.1.1", - "@stdlib/complex-float64-real": "^0.1.1", - "@stdlib/math-base-special-pow": "^0.3.0", - "@stdlib/random-base-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a864c24 --- /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.factory.js b/test/test.factory.js deleted file mode 100644 index 95d35c9..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,2401 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var real = require( '@stdlib/complex-float64-real' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imag = require( '@stdlib/complex-float64-imag' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function (no options)', function test( t ) { - t.strictEqual( typeof factory(), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - t.strictEqual( typeof factory( {} ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided a `highWaterMark` option which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (length)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a function which returns a typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=bool)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, length)', function test( t ) { - var typedarraypool = factory(); - var arr; - - arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=bool, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=bool, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ true, false, false, true ]; - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( v, arr[ 0 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( v, arr[ 1 ], 'returns expected value' ); - - v = out.get( 2 ); - t.strictEqual( v, arr[ 2 ], 'returns expected value' ); - - v = out.get( 3 ); - t.strictEqual( v, arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=bool, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Uint8Array( 0 ); - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8Array( [ 1, 0, 0, 1 ] ); - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( v, true, 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( v, false, 'returns expected value' ); - - v = out.get( 2 ); - t.strictEqual( v, false, 'returns expected value' ); - - v = out.get( 3 ); - t.strictEqual( v, true, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a `malloc` method which is a circular reference', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=bool)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=bool, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'bool' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( Boolean( i%2 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( v, false, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - var buf; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the returned function is a property which returns the pool\'s high water mark', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function supports specifying a high water mark which limits the total amount of memory a pool can allocate', function test( t ) { - var typedarraypool; - var arr1; - var arr2; - - typedarraypool = factory({ - 'highWaterMark': 64 // bytes - }); - - typedarraypool.clear(); - - arr1 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr1.length, 8, 'returns expected value' ); - t.strictEqual( arr1.byteLength, 64, 'returns expected value' ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - typedarraypool.free( arr1 ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Create an array which is less than or equal to the high water mark: - arr2 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr2.length, 8, 'returns expected value' ); - t.strictEqual( arr2.byteLength, 64, 'returns expected value' ); - - typedarraypool.free( arr2 ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a property which returns the total number of accumulated bytes', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var typedarraypool; - var arrs; - var i; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index a4778b2..0000000 --- a/test/test.js +++ /dev/null @@ -1,1935 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var real = require( '@stdlib/complex-float64-real' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imag = require( '@stdlib/complex-float64-imag' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var typedarraypool = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=bool)', function test( t ) { - var arr = typedarraypool( 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=bool, length)', function test( t ) { - var arr = typedarraypool( 10, 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=bool, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ true, false, false, true ]; - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( v, arr[ 0 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( v, arr[ 1 ], 'returns expected value' ); - - v = out.get( 2 ); - t.strictEqual( v, arr[ 2 ], 'returns expected value' ); - - v = out.get( 3 ); - t.strictEqual( v, arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=bool, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Uint8Array( 0 ); - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8Array( [ 1, 0, 0, 1 ] ); - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( v, true, 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( v, false, 'returns expected value' ); - - v = out.get( 2 ); - t.strictEqual( v, false, 'returns expected value' ); - - v = out.get( 3 ); - t.strictEqual( v, true, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=bool)', function test( t ) { - var arr = typedarraypool.calloc( 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=bool, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'bool' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( Boolean( i%2 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( v, false, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -}); From a1e55387885d18552547344858ea2ce5411295a2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 26 May 2025 00:57:34 +0000 Subject: [PATCH 101/103] Transform error messages --- lib/factory.js | 8 ++++---- lib/validate.js | 6 +++--- package.json | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/factory.js b/lib/factory.js index ce4ba27..7f297ce 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -38,7 +38,7 @@ var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); var resolveSetter = require( '@stdlib/array-base-resolve-setter' ); var ARRAY_DEFAULTS = require( '@stdlib/array-defaults' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ArrayBuffer = require( '@stdlib/array-buffer' ); var ceil = require( '@stdlib/math-base-special-ceil' ); var floor = require( '@stdlib/math-base-special-floor' ); @@ -243,7 +243,7 @@ function factory( options ) { } ctor = ctors( dtype ); if ( ctor === null ) { - throw new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) ); + throw new TypeError( format( '01H2Y', dtype ) ); } if ( nargs <= 0 ) { return new ctor( 0 ); @@ -282,7 +282,7 @@ function factory( options ) { } return out; } - throw new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) ); + throw new TypeError( format( '01H2r', arguments[ 0 ] ) ); } /** @@ -350,7 +350,7 @@ function factory( options ) { if ( isTypedArrayLike( buf ) && buf.buffer ) { buf = buf.buffer; } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) ); + throw new TypeError( format( '01H2s', buf ) ); } if ( buf.byteLength > 0 ) { n = floor( log2( buf.byteLength ) ); diff --git a/lib/validate.js b/lib/validate.js index ce54890..da746bb 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -23,7 +23,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' ); var hasOwnProp = require( '@stdlib/assert-has-own-property' ); var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -49,12 +49,12 @@ var format = require( '@stdlib/string-format' ); */ function validate( opts, options ) { if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + return new TypeError( format( '01H2V', options ) ); } if ( hasOwnProp( options, 'highWaterMark' ) ) { opts.highWaterMark = options.highWaterMark; if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'highWaterMark', opts.highWaterMark ) ); + return new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) ); } } return null; diff --git a/package.json b/package.json index b66a8e5..2945498 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "@stdlib/strided-base-reinterpret-boolean": "^0.0.2", "@stdlib/strided-base-reinterpret-complex128": "^0.2.2", "@stdlib/strided-base-reinterpret-complex64": "^0.2.1", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", From b5715c9ebe0800e0ec30d2c95bef77fd629b2928 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 26 May 2025 01:09:43 +0000 Subject: [PATCH 102/103] Remove files --- index.d.ts | 359 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5206 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 8298bf3..0000000 --- a/index.d.ts +++ /dev/null @@ -1,359 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike, RealOrComplexTypedArray, BooleanArray, NumericDataType as DataType } from '@stdlib/types/array'; -import ArrayBuffer = require( '@stdlib/array-buffer' ); - -/** -* Typed array or null. -*/ -type TypedArrayOrNull = RealOrComplexTypedArray | BooleanArray | null; - -/** -* Interface defining pool options. -*/ -interface Options { - /** - * Maximum total memory which can be allocated. - */ - highWaterMark?: number; -} - -/** -* Pool interface. -*/ -interface Pool { - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr = typedarraypool(); - * // returns [] - * - * @example - * var arr = typedarraypool( 'float32' ); - * // returns [] - */ - ( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * // Allocate an array of doubles: - * var arr = typedarraypool( 5, 'float64' ); - * // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * typedarraypool.free( arr ); - * - * @example - * var arr1 = typedarraypool( [ 0.5, 0.5, 0.5 ] ); - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * @example - * var arr1 = [ 0.5, 0.5, 0.5 ]; - * var arr2 = typedarraypool( arr1, 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - */ - ( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc(); - * // returns [] - * - * var arr2 = typedarraypool.calloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param length - typed array length - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.calloc( 5 ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * var arr2 = typedarraypool.calloc( 5, 'uint8' ); - * // returns [ 0, 0, 0, 0, 0 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - calloc( length: number, dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc(); - * // returns [] - * - * var arr2 = typedarraypool.malloc( 'int32' ); - * // returns [] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( dtype?: DataType ): TypedArrayOrNull; - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @param arg - an array length or an array-like object - * @param dtype - data type (default: 'float64') - * @returns typed array or null - * - * @example - * var arr1 = typedarraypool.malloc( 5 ); - * // returns - * - * var arr2 = typedarraypool.malloc( 5, 'uint8' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 5.0, -3.0, 2.0 ] ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr2 = typedarraypool.malloc( arr1 ); - * // returns [ 5.0, -3.0, 2.0 ] - * - * var arr3 = typedarraypool.malloc( arr1, 'int32' ); - * // returns [ 5, -3, 2 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - * typedarraypool.free( arr3 ); - * - * @example - * var arr1 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ] ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * var arr2 = typedarraypool.malloc( [ 0.5, 0.5, 0.5 ], 'float32' ); - * // returns [ 0.5, 0.5, 0.5 ] - * - * // ... - * - * typedarraypool.free( arr1 ); - * typedarraypool.free( arr2 ); - */ - malloc( arg: number | ArrayLike, dtype?: DataType ): TypedArrayOrNull; - - /** - * Frees a typed array or typed array buffer for use in a future allocation. - * - * @param buf - typed array or typed array buffer to free - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array for use in a future allocation: - * typedarraypool.free( arr ); - * - * // Create another typed array: - * arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * // Free the allocated typed array buffer for use in a future allocation: - * typedarraypool.free( arr.buffer ); - */ - free( buf: RealOrComplexTypedArray | BooleanArray | ArrayBuffer ): void; - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @example - * var arr = typedarraypool( 10, 'float64' ); - * // returns - * - * // ... - * - * typedarraypool.free( arr ); - * - * // ... - * - * // Clear all freed buffers: - * typedarraypool.clear(); - */ - clear(): void; - - /** - * Read-only property returning the pool's high water mark. - * - * ## Notes - * - * - Once a high water mark is reached, typed array allocation fails. - * - * @example - * var limit = typedarraypool.highWaterMark; - * // returns - */ - readonly highWaterMark: number; - - /** - * Read-only property returning the total number of allocated bytes. - * - * @example - * var arr = typedarraypool( 5, 'float64' ); - * - * var nbytes = typedarraypool.nbytes; - * // returns - */ - readonly nbytes: number; - - /** - * Creates a typed array pool. - * - * @param options - pool options - * @param options.highWaterMark - maximum total memory which can be allocated - * @throws must provide valid options - * @returns allocator - * - * @example - * var allocator = typedarraypool.factory(); - * - * // Allocate an array of doubles: - * var arr = allocator( 5, 'float64' ); - * // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - * - * arr[ 0 ] = 3.14; - * arr[ 1 ] = 3.14; - * - * // ... - * - * // Free the allocated memory to be used in a future allocation: - * allocator.free( arr ); - */ - factory( options?: Options ): Pool; -} - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @param arg - an array length or an array-like object -* @param dtype - data type (default: 'float64') -* @returns typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -declare var typedarraypool: Pool; - - -// EXPORTS // - -export = typedarraypool; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 0fb5914..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-booleanarray@v0.0.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.3.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.2.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.2-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-setter@v0.2.2-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/array-defaults@v0.3.0-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.2.2-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.2.3-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.3.0-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.3.0-esm/index.mjs";import M from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.2.3-esm/index.mjs";import W from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";var H={bool:1,float64:8,float32:4,int16:2,int32:4,int8:1,uint16:2,uint32:4,uint8:1,uint8c:1,complex64:8,complex128:16},T=g.get("dtypes.default"),L=h("complex64"),P=h("complex128"),V=h("bool");function Y(e){return e instanceof L}function q(e){return e instanceof P}function z(e){return e instanceof V}function A(g){var L,P,V,A;if(V={highWaterMark:9007199254740992},arguments.length&&(A=function(e,t){return W(t)?E(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(u("01H2t","highWaterMark",e.highWaterMark)):null:new TypeError(u("01H2V",t))}(V,g),A))throw A;return P=function(e){var t,r;for(t=[],r=0;r0){for(t=y(k(e.byteLength)),t=M(P.length-1,t),r=P[t],s=0;sV.highWaterMark?null:(t=new b(e),L+=e,t)}(w(t)*H[r]))?s:new e(s,0,t)}function C(){var e,i,n,a,g,b,x,y,w;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:T,null===(n=h(i)))throw new TypeError(u("01H2Y",i));if(e<=0)return new n(0);if(r(arguments[0]))return B(n,arguments[0],i);if(s(arguments[0])){if(y=(a=arguments[0]).length,d(a)?a=j(a,0):m(a)?a=p(a,0):l(a)?a=f(a,0):o(i)&&(y/=2),null===(g=B(n,y,i)))return g;if(q(g)||Y(g)||z(g))return g.set(a),g;for(x=c(a),b=v(g),w=0;w[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '01H2Y', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( isBooleanArray( arr ) ) {\n\t\t\t\tarr = reinterpretBoolean( arr, 0 );\n\t\t\t} else if ( isComplexDataType( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) || isBoolArray( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = resolveGetter( arr );\n\t\t\tset = resolveSetter( out );\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '01H2r', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else if ( isBoolArray( out ) ) {\n\t\t\t\ttmp = reinterpretBoolean( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( '01H2s', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'highWaterMark': 1024\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '01H2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'highWaterMark' ) ) {\n\t\topts.highWaterMark = options.highWaterMark;\n\t\tif ( !isNonNegativeInteger( opts.highWaterMark ) ) {\n\t\t\treturn new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Initializes a cache for pooled typed array buffers.\n*\n* @private\n* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size\n* @returns {ArrayArray} initialized cache\n*/\nfunction pool( n ) {\n\tvar out;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < n+1; i++ ) {\n\t\tout.push( [] );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default pool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DEFAULT_DTYPE","ARRAY_DEFAULTS","get","Complex64Array","ctors","Complex128Array","BooleanArray","isCmplx64Array","arr","isCmplx128Array","isBoolArray","factory","options","nbytes","pool","opts","err","highWaterMark","arguments","length","isObject","hasOwnProp","isNonNegativeInteger","TypeError","format","validate","n","out","i","push","createPool","ceil","log2","setReadOnly","malloc","nargs","tmp","reinterpret128","reinterpret64","reinterpretBoolean","buf","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","setReadOnlyAccessor","typedarray","ctor","len","dtype","pop","ArrayBuffer","arraybuffer","ceil2","BYTES_PER_ELEMENT","set","isString","isCollection","isComplex128Array","isComplex64Array","isBooleanArray","isComplexDataType","resolveGetter","resolveSetter","typedarraypool","main"],"mappings":";;wzFAuDIA,EAAgBC,EAAeC,IAAK,kBACpCC,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cACzBE,EAAeF,EAAO,QAY1B,SAASG,EAAgBC,GACxB,OAASA,aAAeL,CACzB,CASA,SAASM,EAAiBD,GACzB,OAASA,aAAeH,CACzB,CASA,SAASK,EAAaF,GACrB,OAASA,aAAeF,CACzB,CA6BA,SAASK,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,EChGO,CACNE,cAAiB,kBDgGbC,UAAUC,SACdH,EElFF,SAAmBD,EAAMH,GACxB,OAAMQ,EAAUR,GAGXS,EAAYT,EAAS,mBACzBG,EAAKE,cAAgBL,EAAQK,eACvBK,EAAsBP,EAAKE,gBACzB,IAAIM,UAAWC,EAAQ,QAAS,gBAAiBT,EAAKE,gBAGxD,KARC,IAAIM,UAAWC,EAAQ,QAASZ,GASzC,CFuEQa,CAAUV,EAAMH,GACjBI,GACJ,MAAMA,EAaR,OAVAF,EG3GD,SAAeY,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,CHkGQG,CAAYC,EAAMC,EAAMjB,EAAKE,iBACpCJ,EAAS,EAEToB,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,UAiKrB,WACC,IAAIC,EACAR,EACAS,EACAR,EAEJO,EAAQjB,UAAUC,OAEjBQ,EADc,IAAVQ,EACED,IACe,IAAVC,EACLD,EAAQhB,UAAW,IAEnBgB,EAAQhB,UAAW,GAAKA,UAAW,IAE1C,GAAa,OAARS,EAWJ,IARCS,EADI3B,EAAiBkB,GACfU,EAAgBV,EAAK,GAChBpB,EAAgBoB,GACrBW,EAAeX,EAAK,GACfjB,EAAaiB,GAClBY,EAAoBZ,EAAK,GAEzBA,EAEDC,EAAI,EAAGA,EAAIQ,EAAIjB,OAAQS,IAC5BQ,EAAKR,GAAM,EAGb,OAAOD,CACP,IA9LDM,EAAaC,EAAQ,QA4MrB,SAAeM,GACd,IAAId,EACAe,EACAb,EACJ,GAAKc,EAAkBF,IAASA,EAAIG,OACnCH,EAAMA,EAAIG,YACJ,IAAMC,EAAeJ,GAC3B,MAAM,IAAIjB,UAAWC,EAAQ,QAASgB,IAEvC,GAAKA,EAAIK,WAAa,EAAI,CAQzB,IAPAnB,EAAIoB,EAAOd,EAAMQ,EAAIK,aAGrBnB,EAAIqB,EAAKjC,EAAKK,OAAO,EAAGO,GAGxBe,EAAI3B,EAAMY,GACJE,EAAI,EAAGA,EAAIa,EAAEtB,OAAQS,IAC1B,GAAKa,EAAGb,KAAQY,EACf,OAAO,EAITC,EAAEZ,KAAMW,EACR,CACD,OAAO,CACP,IArODP,EAAaC,EAAQ,SA4OrB,WACC,IAAIN,EACJ,IAAMA,EAAI,EAAGA,EAAId,EAAKK,OAAQS,IAC7Bd,EAAMc,GAAIT,OAAS,EAEpBN,EAAS,CACT,IAjPDoB,EAAaC,EAAQ,gBAAiBnB,EAAKE,eAC3C+B,EAAqBd,EAAQ,UAU7B,WACC,OAAOrB,CACP,IAVMqB,EAmDP,SAASe,EAAYC,EAAMC,EAAKC,GAC/B,IAAIZ,EACJ,OAAa,IAARW,EACG,IAAID,EAAM,GAGL,QADbV,EArCD,SAAsBd,GACrB,IAAIc,EACAZ,EAMJ,OAHAA,EAAII,EAAMN,IAGDZ,EAAKK,QAAUL,EAAMc,GAAIT,OAC1BL,EAAMc,GAAIyB,MAGbxC,EAAOa,EAAIX,EAAKE,cACb,MAERuB,EAAM,IAAIc,EAAa5B,GAGvBb,GAAUa,EAEHc,EACP,CAgBMe,CAAaC,EAAOL,GAAMM,EAAmBL,KAE3CZ,EAED,IAAIU,EAAMV,EAAK,EAAGW,EACzB,CAkBD,SAASjB,IACR,IAAIC,EACAiB,EACAF,EACA1C,EACAmB,EACA+B,EACAxD,EACAiD,EACAvB,EAUJ,GALCwB,GAHDjB,EAAQjB,UAAUC,SACJwC,EAAUzC,UAAWiB,EAAM,IAEhCjB,UADRiB,GAAS,GAGDnC,EAGK,QADdkD,EAAO9C,EAAOgD,IAEb,MAAM,IAAI7B,UAAWC,EAAQ,QAAS4B,IAEvC,GAAKjB,GAAS,EACb,OAAO,IAAIe,EAAM,GAGlB,GAAK5B,EAAsBJ,UAAW,IACrC,OAAO+B,EAAYC,EAAMhC,UAAW,GAAKkC,GAG1C,GAAKQ,EAAc1C,UAAW,IAAQ,CAcrC,GAZAiC,GADA3C,EAAMU,UAAW,IACPC,OACL0C,EAAmBrD,GACvBA,EAAM6B,EAAgB7B,EAAK,GAChBsD,EAAkBtD,GAC7BA,EAAM8B,EAAe9B,EAAK,GACfuD,EAAgBvD,GAC3BA,EAAM+B,EAAoB/B,EAAK,GACpBwD,EAAmBZ,KAE9BD,GAAO,GAGK,QADbxB,EAAMsB,EAAYC,EAAMC,EAAKC,IAE5B,OAAOzB,EAER,GAAKlB,EAAiBkB,IAASpB,EAAgBoB,IAASjB,EAAaiB,GAEpE,OADAA,EAAI+B,IAAKlD,GACFmB,EAKR,IAFAzB,EAAM+D,EAAezD,GACrBkD,EAAMQ,EAAevC,GACfC,EAAI,EAAGA,EAAIuB,EAAKvB,IACrB8B,EAAK/B,EAAKC,EAAG1B,EAAKM,EAAKoB,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,QAASN,UAAW,IACjD,CAoGF,CIxUG,IAACiD,EAAiBxD,ICPrBsB,EAAAmC,EAAA,UAAAzD"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a864c24..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From aee4559b4ab9e7937a4809e250cf6530d2b36c6f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 26 May 2025 01:10:10 +0000 Subject: [PATCH 103/103] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 257 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.calloc.js | 265 - benchmark/benchmark.factory.js | 71 - benchmark/benchmark.js | 265 - benchmark/benchmark.length.bool.js | 102 - benchmark/benchmark.length.complex128.js | 102 - benchmark/benchmark.length.complex64.js | 102 - benchmark/benchmark.length.float32.js | 102 - benchmark/benchmark.length.float64.js | 102 - benchmark/benchmark.length.int16.js | 102 - benchmark/benchmark.length.int32.js | 102 - benchmark/benchmark.length.int8.js | 102 - benchmark/benchmark.length.uint16.js | 102 - benchmark/benchmark.length.uint32.js | 102 - benchmark/benchmark.length.uint8.js | 102 - benchmark/benchmark.length.uint8c.js | 102 - benchmark/benchmark.malloc.js | 265 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 53 - dist/index.js.map | 7 - docs/repl.txt | 333 -- docs/types/test.ts | 193 - examples/index.js | 80 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/bytes_per_element.json | 14 - lib/defaults.js | 42 - lib/factory.js | 391 -- lib/index.js | 56 - lib/main.js | 63 - lib/pool.js | 44 - lib/validate.js | 66 - package.json | 104 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.factory.js | 2401 --------- test/test.js | 1935 ------- 65 files changed, 4872 insertions(+), 11534 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.calloc.js delete mode 100644 benchmark/benchmark.factory.js delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/benchmark.length.bool.js delete mode 100644 benchmark/benchmark.length.complex128.js delete mode 100644 benchmark/benchmark.length.complex64.js delete mode 100644 benchmark/benchmark.length.float32.js delete mode 100644 benchmark/benchmark.length.float64.js delete mode 100644 benchmark/benchmark.length.int16.js delete mode 100644 benchmark/benchmark.length.int32.js delete mode 100644 benchmark/benchmark.length.int8.js delete mode 100644 benchmark/benchmark.length.uint16.js delete mode 100644 benchmark/benchmark.length.uint32.js delete mode 100644 benchmark/benchmark.length.uint8.js delete mode 100644 benchmark/benchmark.length.uint8c.js delete mode 100644 benchmark/benchmark.malloc.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 (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/bytes_per_element.json delete mode 100644 lib/defaults.js delete mode 100644 lib/factory.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/pool.js delete mode 100644 lib/validate.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.factory.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 72582c0..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-05-26T00:51:35.181Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 2ea94d9..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/array/pool) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 6f7c875..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/array/pool) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be 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 869c4e9..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: '51 15 * * 4' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -481,7 +478,7 @@ console.log( 'nbytes: %d', typedarray.nbytes ); ## 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]. @@ -548,11 +545,11 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [mdn-arraybuffer]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer -[@stdlib/array/typed-dtypes]: https://github.com/stdlib-js/array-typed-dtypes +[@stdlib/array/typed-dtypes]: https://github.com/stdlib-js/array-typed-dtypes/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/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.calloc.js b/benchmark/benchmark.calloc.js deleted file mode 100644 index 2a04c65..0000000 --- a/benchmark/benchmark.calloc.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var isBooleanArray = require( '@stdlib/assert-is-booleanarray' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':calloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=bool', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'bool' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isBooleanArray( arr ) ) { - b.fail( 'should return a boolean array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':calloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.calloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.factory.js b/benchmark/benchmark.factory.js deleted file mode 100644 index 58918bb..0000000 --- a/benchmark/benchmark.factory.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isFunction = require( '@stdlib/assert-is-function' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':factory', function benchmark( b ) { - var f; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = typedarray.factory(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory:highWaterMark', function benchmark( b ) { - var opts; - var f; - var i; - - opts = { - 'highWaterMark': 0 - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - opts.highWaterMark = i; - f = typedarray.factory( opts ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( f ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 46c6397..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var isBooleanArray = require( '@stdlib/assert-is-booleanarray' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=bool', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'bool' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isBooleanArray( arr ) ) { - b.fail( 'should return a boolean array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/benchmark.length.bool.js b/benchmark/benchmark.length.bool.js deleted file mode 100644 index d9ad47b..0000000 --- a/benchmark/benchmark.length.bool.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isBooleanArray = require( '@stdlib/assert-is-booleanarray' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'bool' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isBooleanArray( arr ) ) { - b.fail( 'should return a boolean array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=bool,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=bool,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=bool,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex128.js b/benchmark/benchmark.length.complex128.js deleted file mode 100644 index 12c6668..0000000 --- a/benchmark/benchmark.length.complex128.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex128' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex128,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex128,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.complex64.js b/benchmark/benchmark.length.complex64.js deleted file mode 100644 index ca2b45c..0000000 --- a/benchmark/benchmark.length.complex64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2022 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'complex64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=complex64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=complex64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float32.js b/benchmark/benchmark.length.float32.js deleted file mode 100644 index b3b4508..0000000 --- a/benchmark/benchmark.length.float32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.float64.js b/benchmark/benchmark.length.float64.js deleted file mode 100644 index 5f0132d..0000000 --- a/benchmark/benchmark.length.float64.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'float64' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=float64,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=float64,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int16.js b/benchmark/benchmark.length.int16.js deleted file mode 100644 index 9f253cb..0000000 --- a/benchmark/benchmark.length.int16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int32.js b/benchmark/benchmark.length.int32.js deleted file mode 100644 index f83e795..0000000 --- a/benchmark/benchmark.length.int32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.int8.js b/benchmark/benchmark.length.int8.js deleted file mode 100644 index 5b01174..0000000 --- a/benchmark/benchmark.length.int8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'int8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=int8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=int8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint16.js b/benchmark/benchmark.length.uint16.js deleted file mode 100644 index 32b0a5d..0000000 --- a/benchmark/benchmark.length.uint16.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint16' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint16,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint16,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint32.js b/benchmark/benchmark.length.uint32.js deleted file mode 100644 index 290b90c..0000000 --- a/benchmark/benchmark.length.uint32.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint32' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint32,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint32,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8.js b/benchmark/benchmark.length.uint8.js deleted file mode 100644 index ff7d733..0000000 --- a/benchmark/benchmark.length.uint8.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.length.uint8c.js b/benchmark/benchmark.length.uint8c.js deleted file mode 100644 index 8f0d10a..0000000 --- a/benchmark/benchmark.length.uint8c.js +++ /dev/null @@ -1,102 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 pow = require( '@stdlib/math-base-special-pow' ); -var isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {Function} fcn - allocation function -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( fcn, len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var arr; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = fcn( len, 'uint8c' ); - if ( arr.length !== len ) { - b.fail( 'unexpected length' ); - } - typedarray.free( arr ); - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( typedarray, len ); - bench( pkg+':dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.malloc, len ); - bench( pkg+':malloc:dtype=uint8c,len='+len, f ); - - f = createBenchmark( typedarray.calloc, len ); - bench( pkg+':calloc:dtype=uint8c,len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.malloc.js b/benchmark/benchmark.malloc.js deleted file mode 100644 index c85d2fb..0000000 --- a/benchmark/benchmark.malloc.js +++ /dev/null @@ -1,265 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF 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 isTypedArray = require( '@stdlib/assert-is-typed-array' ); -var isComplexTypedArray = require( '@stdlib/assert-is-complex-typed-array' ); -var isBooleanArray = require( '@stdlib/assert-is-booleanarray' ); -var pkg = require( './../package.json' ).name; -var typedarray = require( './../lib' ); - - -// MAIN // - -bench( pkg+':malloc', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0 ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=float32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'float32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint32', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint32' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint16', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint16' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=int8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'int8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=uint8c', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'uint8c' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isTypedArray( arr ) ) { - b.fail( 'should return a typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=bool', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'bool' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isBooleanArray( arr ) ) { - b.fail( 'should return a boolean array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex64', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex64' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':malloc:dtype=complex128', function benchmark( b ) { - var arr; - var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr = typedarray.malloc( 0, 'complex128' ); - if ( arr.length !== 0 ) { - b.fail( 'should have length 0' ); - } - } - b.toc(); - if ( !isComplexTypedArray( arr ) ) { - b.fail( 'should return a complex typed array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 612de17..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/array/pool" -%% click B href "https://github.com/stdlib-js/array-pool/tree/main" -%% click C href "https://github.com/stdlib-js/array-pool/tree/production" -%% click D href "https://github.com/stdlib-js/array-pool/tree/esm" -%% click E href "https://github.com/stdlib-js/array-pool/tree/deno" -%% click F href "https://github.com/stdlib-js/array-pool/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/pool -[production-url]: https://github.com/stdlib-js/array-pool/tree/production -[deno-url]: https://github.com/stdlib-js/array-pool/tree/deno -[deno-readme]: https://github.com/stdlib-js/array-pool/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/array-pool/tree/umd -[umd-readme]: https://github.com/stdlib-js/array-pool/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/array-pool/tree/esm -[esm-readme]: https://github.com/stdlib-js/array-pool/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 5160b6f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import typedarraypool from '../docs/types/index'; -export = typedarraypool; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 925147b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,53 +0,0 @@ -"use strict";var s=function(n,i){return function(){return i||n((i={exports:{}}).exports,i),i.exports}};var M=s(function(Cr,w){"use strict";function z(){return{highWaterMark:9007199254740992}}w.exports=z});var T=s(function(Or,E){"use strict";var G=require("@stdlib/assert-is-plain-object"),H=require("@stdlib/assert-has-own-property"),J=require("@stdlib/assert-is-nonnegative-integer").isPrimitive,k=require("@stdlib/string-format");function K(n,i){return G(i)?H(i,"highWaterMark")&&(n.highWaterMark=i.highWaterMark,!J(n.highWaterMark))?new TypeError(k("invalid option. `%s` option must be a nonnegative integer. Option: `%s`.","highWaterMark",n.highWaterMark)):null:new TypeError(k("invalid argument. Options argument must be an object. Value: `%s`.",i))}E.exports=K});var B=s(function(Pr,W){"use strict";function Q(n){var i,u;for(i=[],u=0;uv.highWaterMark?null:(e=new fr(r),i+=r,e)}function d(r,e,t){var a;return e===0?new r(0):(a=F(pr(e)*dr[t]),a===null?a:new r(a,0,e))}function o(){var r,e,t,a,l,A,x,c,f;if(r=arguments.length,r&&Z(arguments[r-1])?(r-=1,e=arguments[r]):e=Ar,t=p(e),t===null)throw new TypeError(y("invalid argument. Must provide a recognized data type. Value: `%s`.",e));if(r<=0)return new t(0);if($(arguments[0]))return d(t,arguments[0],e);if(rr(arguments[0])){if(a=arguments[0],c=a.length,nr(a)?a=O(a,0):ir(a)?a=C(a,0):ur(a)?a=P(a,0):tr(e)&&(c/=2),l=d(t,c,e),l===null)return l;if(R(l)||L(l)||N(l))return l.set(a),l;for(x=lr(a),A=sr(l),f=0;f0){for(e=cr(m(r.byteLength)),e=hr(u.length-1,e),t=u[e],a=0;a[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a recognized data type. Value: `%s`.', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( isBooleanArray( arr ) ) {\n\t\t\t\tarr = reinterpretBoolean( arr, 0 );\n\t\t\t} else if ( isComplexDataType( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) || isBoolArray( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = resolveGetter( arr );\n\t\t\tset = resolveSetter( out );\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either an array length or an array-like object. Value: `%s`.', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else if ( isBoolArray( out ) ) {\n\t\t\t\ttmp = reinterpretBoolean( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Must provide a typed array or ArrayBuffer. Value: `%s`.', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nmodule.exports = typedarraypool;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* var typedarraypool = require( '@stdlib/array-pool' );\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAgCA,SAASC,GAAW,CACnB,MAAO,CACN,cAAiB,gBAClB,CACD,CAKAD,EAAO,QAAUC,ICzCjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAS,QAAS,uBAAwB,EAwB9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMN,EAAUM,CAAQ,EAGnBL,EAAYK,EAAS,eAAgB,IACzCD,EAAK,cAAgBC,EAAQ,cACxB,CAACJ,EAAsBG,EAAK,aAAc,GACvC,IAAI,UAAWF,EAAQ,2EAA4E,gBAAiBE,EAAK,aAAc,CAAE,EAG3I,KARC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAShH,CAKAP,EAAO,QAAUK,ICjEjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cA6BA,SAASC,EAAM,EAAI,CAClB,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAI,EAAE,EAAGA,IACrBD,EAAI,KAAM,CAAC,CAAE,EAEd,OAAOA,CACR,CAKAF,EAAO,QAAUC,IC3CjB,IAAAG,EAAAC,EAAA,SAAAC,GAAAC,EAAA,CAAAA,EAAA,SACC,KAAQ,EACR,QAAW,EACX,QAAW,EACX,MAAS,EACT,MAAS,EACT,KAAQ,EACR,OAAU,EACV,OAAU,EACV,MAAS,EACT,OAAU,EACT,UAAa,EACb,WAAc,EAChB,ICbA,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,GAAe,QAAS,8BAA+B,EACvDC,GAAmB,QAAS,oCAAqC,EACjEC,GAAgB,QAAS,+BAAgC,EACzDC,GAAoB,QAAS,+DAAgE,EAC7FC,GAAmB,QAAS,kCAAmC,EAC/DC,GAAoB,QAAS,mCAAoC,EACjEC,GAAiB,QAAS,gCAAiC,EAC3DC,EAAc,QAAS,uDAAwD,EAC/EC,GAAsB,QAAS,uDAAwD,EACvFC,EAAQ,QAAS,2BAA4B,EAC7CC,EAAgB,QAAS,4CAA6C,EACtEC,EAAiB,QAAS,6CAA8C,EACxEC,EAAqB,QAAS,0CAA2C,EACzEC,GAAgB,QAAS,mCAAoC,EAC7DC,GAAgB,QAAS,mCAAoC,EAC7DC,GAAiB,QAAS,wBAAyB,EACnDC,EAAS,QAAS,uBAAwB,EAC1CC,GAAc,QAAS,sBAAuB,EAC9CC,GAAO,QAAS,gCAAiC,EACjDC,GAAQ,QAAS,iCAAkC,EACnDC,GAAQ,QAAS,iCAAkC,EACnDC,EAAO,QAAS,gCAAiC,EACjDC,GAAM,QAAS,+BAAgC,EAC/CC,GAAW,IACXC,GAAW,IACXC,GAAa,IACbC,GAAoB,IAKpBC,GAAgBZ,GAAe,IAAK,gBAAiB,EACrDa,GAAiBnB,EAAO,WAAY,EACpCoB,GAAkBpB,EAAO,YAAa,EACtCqB,GAAerB,EAAO,MAAO,EAYjC,SAASsB,EAAgBC,EAAM,CAC9B,OAASA,aAAeJ,EACzB,CASA,SAASK,EAAiBD,EAAM,CAC/B,OAASA,aAAeH,EACzB,CASA,SAASK,EAAaF,EAAM,CAC3B,OAASA,aAAeF,EACzB,CA6BA,SAASK,GAASC,EAAU,CAC3B,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,EAAOhB,GAAS,EACX,UAAU,SACdiB,EAAMhB,GAAUe,EAAMH,CAAQ,EACzBI,GACJ,MAAMA,EAGR,OAAAF,EAAOb,GAAYP,GAAMG,EAAMkB,EAAK,aAAc,CAAE,CAAE,EACtDF,EAAS,EAET9B,EAAakC,EAAQ,SAAUA,CAAO,EACtClC,EAAakC,EAAQ,SAAUC,CAAO,EACtCnC,EAAakC,EAAQ,OAAQE,CAAK,EAClCpC,EAAakC,EAAQ,QAASG,CAAM,EACpCrC,EAAakC,EAAQ,gBAAiBF,EAAK,aAAc,EACzD/B,GAAqBiC,EAAQ,SAAUI,CAAS,EAEzCJ,EAQP,SAASI,GAAW,CACnB,OAAOR,CACR,CASA,SAASS,EAAaC,EAAI,CACzB,IAAIC,EACAC,EAMJ,OAHAA,EAAI5B,EAAM0B,CAAE,EAGPE,EAAIX,EAAK,QAAUA,EAAMW,CAAE,EAAE,OAC1BX,EAAMW,CAAE,EAAE,IAAI,EAGjBZ,EAAOU,EAAIR,EAAK,cACb,MAERS,EAAM,IAAI/B,GAAa8B,CAAE,EAGzBV,GAAUU,EAEHC,EACR,CAWA,SAASE,EAAYC,EAAMC,EAAKC,EAAQ,CACvC,IAAIL,EACJ,OAAKI,IAAQ,EACL,IAAID,EAAM,CAAE,GAEpBH,EAAMF,EAAa1B,GAAOgC,CAAI,EAAE1B,GAAmB2B,CAAM,CAAE,EACtDL,IAAQ,KACLA,EAED,IAAIG,EAAMH,EAAK,EAAGI,CAAI,EAC9B,CAkBA,SAASX,GAAS,CACjB,IAAIa,EACAD,EACAF,EACAnB,EACAuB,EACAC,EACAC,EACAL,EACAH,EAUJ,GARAK,EAAQ,UAAU,OACbA,GAASxD,EAAU,UAAWwD,EAAM,CAAE,CAAE,GAC5CA,GAAS,EACTD,EAAQ,UAAWC,CAAM,GAEzBD,EAAQ1B,GAETwB,EAAO1C,EAAO4C,CAAM,EACfF,IAAS,KACb,MAAM,IAAI,UAAWnC,EAAQ,sEAAuEqC,CAAM,CAAE,EAE7G,GAAKC,GAAS,EACb,OAAO,IAAIH,EAAM,CAAE,EAGpB,GAAKpD,EAAsB,UAAW,CAAE,CAAE,EACzC,OAAOmD,EAAYC,EAAM,UAAW,CAAE,EAAGE,CAAM,EAGhD,GAAKrD,GAAc,UAAW,CAAE,CAAE,EAAI,CAcrC,GAbAgC,EAAM,UAAW,CAAE,EACnBoB,EAAMpB,EAAI,OACL3B,GAAmB2B,CAAI,EAC3BA,EAAMrB,EAAgBqB,EAAK,CAAE,EAClB5B,GAAkB4B,CAAI,EACjCA,EAAMtB,EAAesB,EAAK,CAAE,EACjB1B,GAAgB0B,CAAI,EAC/BA,EAAMpB,EAAoBoB,EAAK,CAAE,EACtB7B,GAAmBkD,CAAM,IAEpCD,GAAO,GAERG,EAAML,EAAYC,EAAMC,EAAKC,CAAM,EAC9BE,IAAQ,KACZ,OAAOA,EAER,GAAKtB,EAAiBsB,CAAI,GAAKxB,EAAgBwB,CAAI,GAAKrB,EAAaqB,CAAI,EACxE,OAAAA,EAAI,IAAKvB,CAAI,EACNuB,EAKR,IAFAE,EAAM5C,GAAemB,CAAI,EACzBwB,EAAM1C,GAAeyC,CAAI,EACnBN,EAAI,EAAGA,EAAIG,EAAKH,IACrBO,EAAKD,EAAKN,EAAGQ,EAAKzB,EAAKiB,CAAE,CAAE,EAE5B,OAAOM,CACR,CACA,MAAM,IAAI,UAAWvC,EAAQ,wGAAyG,UAAW,CAAE,CAAE,CAAE,CACxJ,CAgBA,SAAS0B,GAAS,CACjB,IAAIY,EACAC,EACAG,EACAT,EAUJ,GARAK,EAAQ,UAAU,OACbA,IAAU,EACdC,EAAMd,EAAO,EACFa,IAAU,EACrBC,EAAMd,EAAQ,UAAW,CAAE,CAAE,EAE7Bc,EAAMd,EAAQ,UAAW,CAAE,EAAG,UAAW,CAAE,CAAE,EAEzCc,IAAQ,KAWZ,IATKtB,EAAiBsB,CAAI,EACzBG,EAAM/C,EAAgB4C,EAAK,CAAE,EAClBxB,EAAgBwB,CAAI,EAC/BG,EAAMhD,EAAe6C,EAAK,CAAE,EACjBrB,EAAaqB,CAAI,EAC5BG,EAAM9C,EAAoB2C,EAAK,CAAE,EAEjCG,EAAMH,EAEDN,EAAI,EAAGA,EAAIS,EAAI,OAAQT,IAC5BS,EAAKT,CAAE,EAAI,EAGb,OAAOM,CACR,CAcA,SAASZ,EAAMK,EAAM,CACpB,IAAID,EACAY,EACAV,EACJ,GAAKhD,GAAkB+C,CAAI,GAAKA,EAAI,OACnCA,EAAMA,EAAI,eACC,CAAC9C,GAAe8C,CAAI,EAC/B,MAAM,IAAI,UAAWhC,EAAQ,4EAA6EgC,CAAI,CAAE,EAEjH,GAAKA,EAAI,WAAa,EAAI,CAQzB,IAPAD,EAAI5B,GAAOE,EAAM2B,EAAI,UAAW,CAAE,EAGlCD,EAAIzB,GAAKgB,EAAK,OAAO,EAAGS,CAAE,EAG1BY,EAAIrB,EAAMS,CAAE,EACNE,EAAI,EAAGA,EAAIU,EAAE,OAAQV,IAC1B,GAAKU,EAAGV,CAAE,IAAMD,EACf,MAAO,GAITW,EAAE,KAAMX,CAAI,CACb,CACA,MAAO,EACR,CAOA,SAASJ,GAAQ,CAChB,IAAIK,EACJ,IAAMA,EAAI,EAAGA,EAAIX,EAAK,OAAQW,IAC7BX,EAAMW,CAAE,EAAE,OAAS,EAEpBZ,EAAS,CACV,CACD,CAKAxC,EAAO,QAAUsC,KCtYjB,IAAAyB,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAU,IAmCVC,GAAiBD,GAAQ,EAK7BD,EAAO,QAAUE,KCnBjB,IAAIC,GAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,GAAU,IAKdF,GAAaC,EAAM,UAAWC,EAAQ,EAKtC,OAAO,QAAUD", - "names": ["require_defaults", "__commonJSMin", "exports", "module", "defaults", "require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isNonNegativeInteger", "format", "validate", "opts", "options", "require_pool", "__commonJSMin", "exports", "module", "pool", "out", "i", "require_bytes_per_element", "__commonJSMin", "exports", "module", "require_factory", "__commonJSMin", "exports", "module", "isString", "isNonNegativeInteger", "isCollection", "isTypedArrayLike", "isArrayBuffer", "isComplexDataType", "isComplex64Array", "isComplex128Array", "isBooleanArray", "setReadOnly", "setReadOnlyAccessor", "ctors", "reinterpret64", "reinterpret128", "reinterpretBoolean", "resolveGetter", "resolveSetter", "ARRAY_DEFAULTS", "format", "ArrayBuffer", "ceil", "floor", "ceil2", "log2", "min", "defaults", "validate", "createPool", "BYTES_PER_ELEMENT", "DEFAULT_DTYPE", "Complex64Array", "Complex128Array", "BooleanArray", "isCmplx64Array", "arr", "isCmplx128Array", "isBoolArray", "factory", "options", "nbytes", "pool", "opts", "err", "malloc", "calloc", "free", "clear", "getBytes", "arraybuffer", "n", "buf", "i", "typedarray", "ctor", "len", "dtype", "nargs", "out", "set", "get", "tmp", "p", "require_main", "__commonJSMin", "exports", "module", "factory", "typedarraypool", "setReadOnly", "main", "factory"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index a2727d6..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,333 +0,0 @@ - -{{alias}}( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - Memory is **uninitialized**, which means that the contents of a returned - typed array may contain sensitive contents. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}() - [] - > arr = {{alias}}( 'float32' ) - [] - - -{{alias}}( length[, dtype] ) - Returns an uninitialized typed array having a specified length from a typed - array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > arr = {{alias}}( 5, 'int32' ) - - - -{{alias}}( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( [dtype] ) - Returns an uninitialized typed array from a typed array memory pool. - - This method shares the same security vulnerabilities mentioned above. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc() - - > arr = {{alias}}.malloc( 'float32' ) - - - -{{alias}}.malloc( length[, dtype] ) - Returns a typed array having a specified length from a typed array memory - pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.malloc( 5 ) - - > arr = {{alias}}.malloc( 5, 'int32' ) - - - -{{alias}}.malloc( typedarray[, dtype] ) - Creates a pooled typed array from another typed array. - - Parameters - ---------- - typedarray: TypedArray - Typed array from which to generate another typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = {{alias}}.malloc( [ 0.5, 0.5, 0.5 ] ); - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.malloc( obj[, dtype] ) - Creates a pooled typed array from an array-like object. - - Parameters - ---------- - obj: Object - Array-like object from which to generate a typed array. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr1 = [ 0.5, 0.5, 0.5 ]; - > var arr2 = {{alias}}.malloc( arr1, 'float32' ) - [ 0.5, 0.5, 0.5 ] - - -{{alias}}.calloc( [dtype] ) - Returns a zero-initialized typed array from a typed array memory pool. - - Parameters - ---------- - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc() - [] - > arr = {{alias}}.calloc( 'float32' ) - [] - - -{{alias}}.calloc( length[, dtype] ) - Returns a zero-initialized typed array having a specified length from a - typed array memory pool. - - Parameters - ---------- - length: integer - Typed array length. - - dtype: string (optional) - Data type. Default: 'float64'. - - Returns - ------- - out: TypedArray|null - If the function is unable to allocate a typed array from the typed array - pool (e.g., due to insufficient memory), the function returns `null`. - - Examples - -------- - > var arr = {{alias}}.calloc( 5 ) - [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - > arr = {{alias}}.calloc( 5, 'int32' ) - [ 0, 0, 0, 0, 0 ] - - -{{alias}}.free( buf ) - Frees a typed array or typed array buffer for use in a future allocation. - - Parameters - ---------- - buf: TypedArray|ArrayBuffer - Typed array or typed array buffer to free. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - - -{{alias}}.clear() - Clears the typed array pool allowing garbage collection of previously - allocated (and currently free) array buffers. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.free( arr ); - > {{alias}}.clear(); - - -{{alias}}.highWaterMark - Read-only property returning the pool's high water mark. - - Once a high water mark is reached, typed array allocation fails. - - Examples - -------- - > {{alias}}.highWaterMark - - - -{{alias}}.nbytes - Read-only property returning the total number of allocated bytes. - - The returned value is the total accumulated value. Hence, anytime a pool - must allocate a new array buffer (i.e., more memory), the pool increments - this value. - - The only time this value is decremented is when a pool is cleared. - - This behavior means that, while allocated buffers which are never freed may, - in fact, be garbage collected, they continue to count against the high water - mark limit. - - Accordingly, you should *always* free allocated buffers in order to prevent - the pool from believing that non-freed buffers are continually in use. - - Examples - -------- - > var arr = {{alias}}( 5 ) - - > {{alias}}.nbytes - - - -{{alias}}.factory( [options] ) - Creates a typed array pool. - - Parameters - ---------- - options: Object (optional) - Function options. - - options.highWaterMark: integer (optional) - Maximum total memory (in bytes) which can be allocated. - - Returns - ------- - fcn: Function - Function for creating typed arrays from a typed array memory pool. - - Examples - -------- - > var pool = {{alias}}.factory(); - > var arr1 = pool( 3, 'float64' ) - - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 4336c42..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,193 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-empty */ -/* eslint-disable @typescript-eslint/no-unused-expressions */ - -import typedarraypool = require( './index' ); - - -// TESTS // - -// The function returns a typed array or null... -{ - typedarraypool(); // $ExpectType TypedArrayOrNull - typedarraypool( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the function is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool( true ); // $ExpectError - typedarraypool( false ); // $ExpectError - typedarraypool( null ); // $ExpectError - typedarraypool( {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a recognized data type... -{ - typedarraypool( 4, true ); // $ExpectError - typedarraypool( 4, false ); // $ExpectError - typedarraypool( 4, null ); // $ExpectError - typedarraypool( 4, 'abc' ); // $ExpectError - typedarraypool( 4, 123 ); // $ExpectError - typedarraypool( 4, [] ); // $ExpectError - typedarraypool( 4, {} ); // $ExpectError - typedarraypool( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an incorrect number of arguments... -{ - typedarraypool( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `malloc` method which returns a typed array or null... -{ - typedarraypool.malloc(); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull - typedarraypool.malloc( [ 1, 2, 3 ] ); // $ExpectType TypedArrayOrNull - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.malloc( arr, 'float64' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `malloc` method is provided a first argument which is neither a number nor array-like object... -{ - typedarraypool.malloc( true ); // $ExpectError - typedarraypool.malloc( false ); // $ExpectError - typedarraypool.malloc( null ); // $ExpectError - typedarraypool.malloc( {} ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.malloc( 4, true ); // $ExpectError - typedarraypool.malloc( 4, false ); // $ExpectError - typedarraypool.malloc( 4, null ); // $ExpectError - typedarraypool.malloc( 4, 'abc' ); // $ExpectError - typedarraypool.malloc( 4, 123 ); // $ExpectError - typedarraypool.malloc( 4, [] ); // $ExpectError - typedarraypool.malloc( 4, {} ); // $ExpectError - typedarraypool.malloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `malloc` method is provided an incorrect number of arguments... -{ - typedarraypool.malloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `calloc` method which returns a typed array or null... -{ - typedarraypool.calloc(); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 'float32' ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12 ); // $ExpectType TypedArrayOrNull - typedarraypool.calloc( 12, 'int32' ); // $ExpectType TypedArrayOrNull -} - -// The compiler throws an error if the `calloc` method is provided a first argument which is not a number... -{ - typedarraypool.calloc( 'abc' ); // $ExpectError - typedarraypool.calloc( true ); // $ExpectError - typedarraypool.calloc( false ); // $ExpectError - typedarraypool.calloc( null ); // $ExpectError - typedarraypool.calloc( {} ); // $ExpectError - typedarraypool.calloc( [] ); // $ExpectError - typedarraypool.calloc( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided a second argument which is not a recognized data type... -{ - typedarraypool.calloc( 4, true ); // $ExpectError - typedarraypool.calloc( 4, false ); // $ExpectError - typedarraypool.calloc( 4, null ); // $ExpectError - typedarraypool.calloc( 4, 'abc' ); // $ExpectError - typedarraypool.calloc( 4, 123 ); // $ExpectError - typedarraypool.calloc( 4, [] ); // $ExpectError - typedarraypool.calloc( 4, {} ); // $ExpectError - typedarraypool.calloc( 4, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `calloc` method is provided an incorrect number of arguments... -{ - typedarraypool.calloc( 4, 'int32', {} ); // $ExpectError -} - -// Attached to the main export is a `factory` method which returns a typed array pool.. -{ - typedarraypool.factory(); // $ExpectType Pool - typedarraypool.factory( { 'highWaterMark': 556 } ); // $ExpectType Pool -} - -// The compiler throws an error if the `factory` method is provided a `highWaterMark` option which is not a number... -{ - typedarraypool.factory( { 'highWaterMark': true } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': false } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': 'abc' } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': null } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': [] } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': {} } ); // $ExpectError - typedarraypool.factory( { 'highWaterMark': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided an incorrect number of arguments... -{ - typedarraypool.factory( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `free` method which returns void... -{ - const arr = new Int32Array( [ 2, 5, 5, 7 ] ); - typedarraypool.free( arr ); // $ExpectType void -} - -// The compiler throws an error if the `free` method is provided a first argument which is neither a typed array nor array buffer... -{ - typedarraypool.free( true ); // $ExpectError - typedarraypool.free( false ); // $ExpectError - typedarraypool.free( 123 ); // $ExpectError - typedarraypool.free( 'abc' ); // $ExpectError - typedarraypool.free( null ); // $ExpectError - typedarraypool.free( {} ); // $ExpectError - typedarraypool.free( ( x: number ): number => x ); // $ExpectError -} - -// Attached to the main export is a `clear` method which returns void... -{ - typedarraypool.clear(); // $ExpectType void -} - -// The compiler throws an error if the `clear` method is provided arguments... -{ - typedarraypool.clear( {} ); // $ExpectError - typedarraypool.clear( {}, {} ); // $ExpectError -} - -// Attached to the main export is a `highWaterMark` property... -{ - typedarraypool.highWaterMark; // $ExpectType number -} - -// Attached to the main export is a `nbytes` property... -{ - typedarraypool.nbytes; // $ExpectType number -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 24a7846..0000000 --- a/examples/index.js +++ /dev/null @@ -1,80 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR 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 randu = require( '@stdlib/random-base-randu' ); -var typedarraypool = require( './../lib' ); - -// Create a typed array pool which can allocate at most 1GB: -var typedarray = typedarraypool.factory({ - 'highWaterMark': 1e9 -}); - -// Inspect the pool: -console.log( 'Max bytes: %d', typedarray.highWaterMark ); -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Allocate an array for storing double-precision floating-point numbers: -var arr1 = typedarray( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); - -// Fill the array... -var i; -for ( i = 0; i < arr1.length; i++ ) { - arr1[ i ] = randu(); -} - -// Inspect array contents: -console.log( arr1 ); - -// Free the array: -typedarray.free( arr1 ); - -// Allocate another array similar to the previous one: -var arr2 = typedarray( 5, 'float64' ); -// returns - -// Check that we have been returned a new typed array view: -console.log( arr2 === arr1 ); -// => false - -// Inspect array contents: -console.log( arr2 ); - -// Free the array: -typedarray.free( arr2 ); - -// Allocate an initialized array: -var arr3 = typedarray.calloc( 5, 'float64' ); -// returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] - -// Inspect array contents: -console.log( arr3 ); - -// Free the array: -typedarray.free( arr3 ); - -// Clear the pool: -typedarray.clear(); - -// Inspect the pool: -console.log( 'nbytes: %d', typedarray.nbytes ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 4dc8736..8298bf3 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike, RealOrComplexTypedArray, BooleanArray, NumericDataType as DataType } from '@stdlib/types/array'; import ArrayBuffer = require( '@stdlib/array-buffer' ); diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..326b11f --- /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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-property@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-string@v0.2.2-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-typed-array-like@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-arraybuffer@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-assert-is-complex-floating-point-data-type@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex64array@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-complex128array@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-booleanarray@v0.0.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-define-nonenumerable-read-only-accessor@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/array-typed-ctors@v0.3.0-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex64@v0.2.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-complex128@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/strided-base-reinterpret-boolean@v0.0.2-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-getter@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-resolve-setter@v0.2.2-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/array-defaults@v0.3.0-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-buffer@v0.2.2-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil@v0.2.2-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-floor@v0.2.3-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-ceil2@v0.3.0-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-log2@v0.3.0-esm/index.mjs";import M from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-min@v0.2.3-esm/index.mjs";import W from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";var H={bool:1,float64:8,float32:4,int16:2,int32:4,int8:1,uint16:2,uint32:4,uint8:1,uint8c:1,complex64:8,complex128:16},T=g.get("dtypes.default"),L=h("complex64"),P=h("complex128"),V=h("bool");function Y(e){return e instanceof L}function q(e){return e instanceof P}function z(e){return e instanceof V}function A(g){var L,P,V,A;if(V={highWaterMark:9007199254740992},arguments.length&&(A=function(e,t){return W(t)?E(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!r(e.highWaterMark))?new TypeError(u("01H2t","highWaterMark",e.highWaterMark)):null:new TypeError(u("01H2V",t))}(V,g),A))throw A;return P=function(e){var t,r;for(t=[],r=0;r0){for(t=y(k(e.byteLength)),t=M(P.length-1,t),r=P[t],s=0;sV.highWaterMark?null:(t=new b(e),L+=e,t)}(w(t)*H[r]))?s:new e(s,0,t)}function C(){var e,i,n,a,g,b,x,y,w;if(i=(e=arguments.length)&&t(arguments[e-1])?arguments[e-=1]:T,null===(n=h(i)))throw new TypeError(u("01H2Y",i));if(e<=0)return new n(0);if(r(arguments[0]))return B(n,arguments[0],i);if(s(arguments[0])){if(y=(a=arguments[0]).length,d(a)?a=j(a,0):m(a)?a=p(a,0):l(a)?a=f(a,0):o(i)&&(y/=2),null===(g=B(n,y,i)))return g;if(q(g)||Y(g)||z(g))return g.set(a),g;for(x=c(a),b=v(g),w=0;w[ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nfunction factory( options ) {\n\tvar nbytes;\n\tvar pool;\n\tvar opts;\n\tvar err;\n\n\topts = defaults();\n\tif ( arguments.length ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t}\n\tpool = createPool( ceil( log2( opts.highWaterMark ) ) );\n\tnbytes = 0;\n\n\tsetReadOnly( malloc, 'malloc', malloc ); // circular reference\n\tsetReadOnly( malloc, 'calloc', calloc );\n\tsetReadOnly( malloc, 'free', free );\n\tsetReadOnly( malloc, 'clear', clear );\n\tsetReadOnly( malloc, 'highWaterMark', opts.highWaterMark );\n\tsetReadOnlyAccessor( malloc, 'nbytes', getBytes );\n\n\treturn malloc;\n\n\t/**\n\t* Returns the number of allocated bytes.\n\t*\n\t* @private\n\t* @returns {NonNegativeInteger} number of allocated bytes\n\t*/\n\tfunction getBytes() {\n\t\treturn nbytes;\n\t}\n\n\t/**\n\t* Returns an array buffer.\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} n - number of bytes\n\t* @returns {(ArrayBuffer|null)} array buffer or null\n\t*/\n\tfunction arraybuffer( n ) {\n\t\tvar buf;\n\t\tvar i;\n\n\t\t// Convert the number of bytes to an index in our pool table:\n\t\ti = log2( n );\n\n\t\t// If we already have an available array buffer, use it...\n\t\tif ( i < pool.length && pool[ i ].length ) {\n\t\t\treturn pool[ i ].pop();\n\t\t}\n\t\t// Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate...\n\t\tif ( nbytes+n > opts.highWaterMark ) {\n\t\t\treturn null;\n\t\t}\n\t\tbuf = new ArrayBuffer( n );\n\n\t\t// Update the running counter of allocated bytes:\n\t\tnbytes += n;\n\n\t\treturn buf;\n\t}\n\n\t/**\n\t* Returns a typed array.\n\t*\n\t* @private\n\t* @param {Function} ctor - typed array constructor\n\t* @param {NonNegativeInteger} len - view length\n\t* @param {string} dtype - data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction typedarray( ctor, len, dtype ) {\n\t\tvar buf;\n\t\tif ( len === 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\tbuf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] );\n\t\tif ( buf === null ) {\n\t\t\treturn buf;\n\t\t}\n\t\treturn new ctor( buf, 0, len );\n\t}\n\n\t/**\n\t* Returns an uninitialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - Memory is **not** initialized.\n\t* - Memory is lazily allocated.\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length or an array-like object\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction malloc() {\n\t\tvar nargs;\n\t\tvar dtype;\n\t\tvar ctor;\n\t\tvar arr;\n\t\tvar out;\n\t\tvar set;\n\t\tvar get;\n\t\tvar len;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs && isString( arguments[ nargs-1 ] ) ) {\n\t\t\tnargs -= 1;\n\t\t\tdtype = arguments[ nargs ];\n\t\t} else {\n\t\t\tdtype = DEFAULT_DTYPE;\n\t\t}\n\t\tctor = ctors( dtype );\n\t\tif ( ctor === null ) {\n\t\t\tthrow new TypeError( format( '01H2Y', dtype ) );\n\t\t}\n\t\tif ( nargs <= 0 ) {\n\t\t\treturn new ctor( 0 );\n\t\t}\n\t\t// Check if provided a typed array length...\n\t\tif ( isNonNegativeInteger( arguments[ 0 ] ) ) {\n\t\t\treturn typedarray( ctor, arguments[ 0 ], dtype );\n\t\t}\n\t\t// Check if provided an array-like object containing data elements...\n\t\tif ( isCollection( arguments[ 0 ] ) ) {\n\t\t\tarr = arguments[ 0 ];\n\t\t\tlen = arr.length;\n\t\t\tif ( isComplex128Array( arr ) ) {\n\t\t\t\tarr = reinterpret128( arr, 0 );\n\t\t\t} else if ( isComplex64Array( arr ) ) {\n\t\t\t\tarr = reinterpret64( arr, 0 );\n\t\t\t} else if ( isBooleanArray( arr ) ) {\n\t\t\t\tarr = reinterpretBoolean( arr, 0 );\n\t\t\t} else if ( isComplexDataType( dtype ) ) {\n\t\t\t\t// Assume we've been provided an array of interleaved real and imaginary components...\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tout = typedarray( ctor, len, dtype );\n\t\t\tif ( out === null ) {\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif ( isCmplx128Array( out ) || isCmplx64Array( out ) || isBoolArray( out ) ) {\n\t\t\t\tout.set( arr );\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\t// Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other \"unsafe\" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things...\n\t\t\tget = resolveGetter( arr );\n\t\t\tset = resolveSetter( out );\n\t\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\t\tset( out, i, get( arr, i ) );\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t\tthrow new TypeError( format( '01H2r', arguments[ 0 ] ) );\n\t}\n\n\t/**\n\t* Returns a zero-initialized typed array.\n\t*\n\t* ## Notes\n\t*\n\t* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n\t*\n\t* @private\n\t* @param {NonNegativeInteger} [len=0] - array length\n\t* @param {string} [dtype=\"float64\"] - data type\n\t* @throws {TypeError} must provide a valid array length\n\t* @throws {TypeError} must provide a recognized data type\n\t* @returns {(TypedArray|null)} typed array or null\n\t*/\n\tfunction calloc() {\n\t\tvar nargs;\n\t\tvar out;\n\t\tvar tmp;\n\t\tvar i;\n\n\t\tnargs = arguments.length;\n\t\tif ( nargs === 0 ) {\n\t\t\tout = malloc();\n\t\t} else if ( nargs === 1 ) {\n\t\t\tout = malloc( arguments[ 0 ] );\n\t\t} else {\n\t\t\tout = malloc( arguments[ 0 ], arguments[ 1 ] );\n\t\t}\n\t\tif ( out !== null ) {\n\t\t\t// Initialize the memory...\n\t\t\tif ( isCmplx128Array( out ) ) {\n\t\t\t\ttmp = reinterpret128( out, 0 );\n\t\t\t} else if ( isCmplx64Array( out ) ) {\n\t\t\t\ttmp = reinterpret64( out, 0 );\n\t\t\t} else if ( isBoolArray( out ) ) {\n\t\t\t\ttmp = reinterpretBoolean( out, 0 );\n\t\t\t} else {\n\t\t\t\ttmp = out;\n\t\t\t}\n\t\t\tfor ( i = 0; i < tmp.length; i++ ) {\n\t\t\t\ttmp[ i ] = 0.0;\n\t\t\t}\n\t\t}\n\t\treturn out;\n\t}\n\n\t/**\n\t* Frees a typed array or typed array buffer.\n\t*\n\t* ## Notes\n\t*\n\t* - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., \"freeing\" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool.\n\t*\n\t* @private\n\t* @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free\n\t* @throws {TypeError} must provide a typed array or typed array buffer\n\t* @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed\n\t*/\n\tfunction free( buf ) {\n\t\tvar n;\n\t\tvar p;\n\t\tvar i;\n\t\tif ( isTypedArrayLike( buf ) && buf.buffer ) {\n\t\t\tbuf = buf.buffer;\n\t\t} else if ( !isArrayBuffer( buf ) ) {\n\t\t\tthrow new TypeError( format( '01H2s', buf ) );\n\t\t}\n\t\tif ( buf.byteLength > 0 ) {\n\t\t\tn = floor( log2( buf.byteLength ) );\n\n\t\t\t// Prohibit \"freeing\" array buffers which would potentially allow users to circumvent high water mark limits:\n\t\t\tn = min( pool.length-1, n );\n\n\t\t\t// Ensure that we do not attempt to free the same buffer more than once...\n\t\t\tp = pool[ n ];\n\t\t\tfor ( i = 0; i < p.length; i++ ) {\n\t\t\t\tif ( p[ i ] === buf ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Add the buffer to our pool of free buffers:\n\t\t\tp.push( buf );\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t* Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers.\n\t*\n\t* @private\n\t*/\n\tfunction clear() {\n\t\tvar i;\n\t\tfor ( i = 0; i < pool.length; i++ ) {\n\t\t\tpool[ i ].length = 0;\n\t\t}\n\t\tnbytes = 0;\n\t}\n}\n\n\n// EXPORTS //\n\nexport default factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2023 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns default options.\n*\n* @private\n* @returns {Object} default options\n*\n* @example\n* var o = defaults();\n* // returns {...}\n*/\nfunction defaults() {\n\treturn {\n\t\t'highWaterMark': 9007199254740992\n\t};\n}\n\n\n// EXPORTS //\n\nexport default defaults;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isObject from '@stdlib/assert-is-plain-object';\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'highWaterMark': 1024\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( '01H2V', options ) );\n\t}\n\tif ( hasOwnProp( options, 'highWaterMark' ) ) {\n\t\topts.highWaterMark = options.highWaterMark;\n\t\tif ( !isNonNegativeInteger( opts.highWaterMark ) ) {\n\t\t\treturn new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nexport default validate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Initializes a cache for pooled typed array buffers.\n*\n* @private\n* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size\n* @returns {ArrayArray} initialized cache\n*/\nfunction pool( n ) {\n\tvar out;\n\tvar i;\n\n\tout = [];\n\tfor ( i = 0; i < n+1; i++ ) {\n\t\tout.push( [] );\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default pool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport factory from './factory.js';\n\n\n// MAIN //\n\n/**\n* Returns an uninitialized typed array.\n*\n* ## Notes\n*\n* - Memory is **not** initialized.\n* - Memory is lazily allocated.\n* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory).\n*\n* @name typedarraypool\n* @type {Function}\n* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object\n* @param {string} [dtype=\"float64\"] - data type\n* @throws {TypeError} must provide a valid array length or an array-like object\n* @throws {TypeError} must provide a recognized data type\n* @returns {(TypedArray|null)} typed array or null\n*\n* @example\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\nvar typedarraypool = factory();\n\n\n// EXPORTS //\n\nexport default typedarraypool;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Typed array pool.\n*\n* @module @stdlib/array-pool\n*\n* @example\n* import typedarraypool from '@stdlib/array-pool';\n*\n* // Allocate an array of doubles:\n* var arr = typedarraypool( 5, 'float64' );\n* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ]\n*\n* arr[ 0 ] = 3.14;\n* arr[ 1 ] = 3.14;\n*\n* // ...\n*\n* // Free the allocated memory to be used in a future allocation:\n* typedarraypool.free( arr );\n*/\n\n// MODULES //\n\nimport setReadOnly from '@stdlib/utils-define-nonenumerable-read-only-property';\nimport main from './main.js';\nimport factory from './factory.js';\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nexport default main;\n"],"names":["DEFAULT_DTYPE","ARRAY_DEFAULTS","get","Complex64Array","ctors","Complex128Array","BooleanArray","isCmplx64Array","arr","isCmplx128Array","isBoolArray","factory","options","nbytes","pool","opts","err","highWaterMark","arguments","length","isObject","hasOwnProp","isNonNegativeInteger","TypeError","format","validate","n","out","i","push","createPool","ceil","log2","setReadOnly","malloc","nargs","tmp","reinterpret128","reinterpret64","reinterpretBoolean","buf","p","isTypedArrayLike","buffer","isArrayBuffer","byteLength","floor","min","setReadOnlyAccessor","typedarray","ctor","len","dtype","pop","ArrayBuffer","arraybuffer","ceil2","BYTES_PER_ELEMENT","set","isString","isCollection","isComplex128Array","isComplex64Array","isBooleanArray","isComplexDataType","resolveGetter","resolveSetter","typedarraypool","main"],"mappings":";;wzFAuDIA,EAAgBC,EAAeC,IAAK,kBACpCC,EAAiBC,EAAO,aACxBC,EAAkBD,EAAO,cACzBE,EAAeF,EAAO,QAY1B,SAASG,EAAgBC,GACxB,OAASA,aAAeL,CACzB,CASA,SAASM,EAAiBD,GACzB,OAASA,aAAeH,CACzB,CASA,SAASK,EAAaF,GACrB,OAASA,aAAeF,CACzB,CA6BA,SAASK,EAASC,GACjB,IAAIC,EACAC,EACAC,EACAC,EAGJ,GADAD,EChGO,CACNE,cAAiB,kBDgGbC,UAAUC,SACdH,EElFF,SAAmBD,EAAMH,GACxB,OAAMQ,EAAUR,GAGXS,EAAYT,EAAS,mBACzBG,EAAKE,cAAgBL,EAAQK,eACvBK,EAAsBP,EAAKE,gBACzB,IAAIM,UAAWC,EAAQ,QAAS,gBAAiBT,EAAKE,gBAGxD,KARC,IAAIM,UAAWC,EAAQ,QAASZ,GASzC,CFuEQa,CAAUV,EAAMH,GACjBI,GACJ,MAAMA,EAaR,OAVAF,EG3GD,SAAeY,GACd,IAAIC,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAE,EAAGE,IACrBD,EAAIE,KAAM,IAEX,OAAOF,CACR,CHkGQG,CAAYC,EAAMC,EAAMjB,EAAKE,iBACpCJ,EAAS,EAEToB,EAAaC,EAAQ,SAAUA,GAC/BD,EAAaC,EAAQ,UAiKrB,WACC,IAAIC,EACAR,EACAS,EACAR,EAEJO,EAAQjB,UAAUC,OAEjBQ,EADc,IAAVQ,EACED,IACe,IAAVC,EACLD,EAAQhB,UAAW,IAEnBgB,EAAQhB,UAAW,GAAKA,UAAW,IAE1C,GAAa,OAARS,EAWJ,IARCS,EADI3B,EAAiBkB,GACfU,EAAgBV,EAAK,GAChBpB,EAAgBoB,GACrBW,EAAeX,EAAK,GACfjB,EAAaiB,GAClBY,EAAoBZ,EAAK,GAEzBA,EAEDC,EAAI,EAAGA,EAAIQ,EAAIjB,OAAQS,IAC5BQ,EAAKR,GAAM,EAGb,OAAOD,CACP,IA9LDM,EAAaC,EAAQ,QA4MrB,SAAeM,GACd,IAAId,EACAe,EACAb,EACJ,GAAKc,EAAkBF,IAASA,EAAIG,OACnCH,EAAMA,EAAIG,YACJ,IAAMC,EAAeJ,GAC3B,MAAM,IAAIjB,UAAWC,EAAQ,QAASgB,IAEvC,GAAKA,EAAIK,WAAa,EAAI,CAQzB,IAPAnB,EAAIoB,EAAOd,EAAMQ,EAAIK,aAGrBnB,EAAIqB,EAAKjC,EAAKK,OAAO,EAAGO,GAGxBe,EAAI3B,EAAMY,GACJE,EAAI,EAAGA,EAAIa,EAAEtB,OAAQS,IAC1B,GAAKa,EAAGb,KAAQY,EACf,OAAO,EAITC,EAAEZ,KAAMW,EACR,CACD,OAAO,CACP,IArODP,EAAaC,EAAQ,SA4OrB,WACC,IAAIN,EACJ,IAAMA,EAAI,EAAGA,EAAId,EAAKK,OAAQS,IAC7Bd,EAAMc,GAAIT,OAAS,EAEpBN,EAAS,CACT,IAjPDoB,EAAaC,EAAQ,gBAAiBnB,EAAKE,eAC3C+B,EAAqBd,EAAQ,UAU7B,WACC,OAAOrB,CACP,IAVMqB,EAmDP,SAASe,EAAYC,EAAMC,EAAKC,GAC/B,IAAIZ,EACJ,OAAa,IAARW,EACG,IAAID,EAAM,GAGL,QADbV,EArCD,SAAsBd,GACrB,IAAIc,EACAZ,EAMJ,OAHAA,EAAII,EAAMN,IAGDZ,EAAKK,QAAUL,EAAMc,GAAIT,OAC1BL,EAAMc,GAAIyB,MAGbxC,EAAOa,EAAIX,EAAKE,cACb,MAERuB,EAAM,IAAIc,EAAa5B,GAGvBb,GAAUa,EAEHc,EACP,CAgBMe,CAAaC,EAAOL,GAAMM,EAAmBL,KAE3CZ,EAED,IAAIU,EAAMV,EAAK,EAAGW,EACzB,CAkBD,SAASjB,IACR,IAAIC,EACAiB,EACAF,EACA1C,EACAmB,EACA+B,EACAxD,EACAiD,EACAvB,EAUJ,GALCwB,GAHDjB,EAAQjB,UAAUC,SACJwC,EAAUzC,UAAWiB,EAAM,IAEhCjB,UADRiB,GAAS,GAGDnC,EAGK,QADdkD,EAAO9C,EAAOgD,IAEb,MAAM,IAAI7B,UAAWC,EAAQ,QAAS4B,IAEvC,GAAKjB,GAAS,EACb,OAAO,IAAIe,EAAM,GAGlB,GAAK5B,EAAsBJ,UAAW,IACrC,OAAO+B,EAAYC,EAAMhC,UAAW,GAAKkC,GAG1C,GAAKQ,EAAc1C,UAAW,IAAQ,CAcrC,GAZAiC,GADA3C,EAAMU,UAAW,IACPC,OACL0C,EAAmBrD,GACvBA,EAAM6B,EAAgB7B,EAAK,GAChBsD,EAAkBtD,GAC7BA,EAAM8B,EAAe9B,EAAK,GACfuD,EAAgBvD,GAC3BA,EAAM+B,EAAoB/B,EAAK,GACpBwD,EAAmBZ,KAE9BD,GAAO,GAGK,QADbxB,EAAMsB,EAAYC,EAAMC,EAAKC,IAE5B,OAAOzB,EAER,GAAKlB,EAAiBkB,IAASpB,EAAgBoB,IAASjB,EAAaiB,GAEpE,OADAA,EAAI+B,IAAKlD,GACFmB,EAKR,IAFAzB,EAAM+D,EAAezD,GACrBkD,EAAMQ,EAAevC,GACfC,EAAI,EAAGA,EAAIuB,EAAKvB,IACrB8B,EAAK/B,EAAKC,EAAG1B,EAAKM,EAAKoB,IAExB,OAAOD,CACP,CACD,MAAM,IAAIJ,UAAWC,EAAQ,QAASN,UAAW,IACjD,CAoGF,CIxUG,IAACiD,EAAiBxD,ICPrBsB,EAAAmC,EAAA,UAAAzD"} \ No newline at end of file diff --git a/lib/bytes_per_element.json b/lib/bytes_per_element.json deleted file mode 100644 index 30f02fc..0000000 --- a/lib/bytes_per_element.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "bool": 1, - "float64": 8, - "float32": 4, - "int16": 2, - "int32": 4, - "int8": 1, - "uint16": 2, - "uint32": 4, - "uint8": 1, - "uint8c": 1, - "complex64": 8, - "complex128": 16 -} diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index a421711..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,42 +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'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'highWaterMark': 9007199254740992 - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/factory.js b/lib/factory.js deleted file mode 100644 index 7f297ce..0000000 --- a/lib/factory.js +++ /dev/null @@ -1,391 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert-is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isCollection = require( '@stdlib/assert-is-collection' ); -var isTypedArrayLike = require( '@stdlib/assert-is-typed-array-like' ); -var isArrayBuffer = require( '@stdlib/assert-is-arraybuffer' ); -var isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' ); -var isComplex64Array = require( '@stdlib/assert-is-complex64array' ); -var isComplex128Array = require( '@stdlib/assert-is-complex128array' ); -var isBooleanArray = require( '@stdlib/assert-is-booleanarray' ); -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils-define-nonenumerable-read-only-accessor' ); -var ctors = require( '@stdlib/array-typed-ctors' ); -var reinterpret64 = require( '@stdlib/strided-base-reinterpret-complex64' ); -var reinterpret128 = require( '@stdlib/strided-base-reinterpret-complex128' ); -var reinterpretBoolean = require( '@stdlib/strided-base-reinterpret-boolean' ); -var resolveGetter = require( '@stdlib/array-base-resolve-getter' ); -var resolveSetter = require( '@stdlib/array-base-resolve-setter' ); -var ARRAY_DEFAULTS = require( '@stdlib/array-defaults' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ArrayBuffer = require( '@stdlib/array-buffer' ); -var ceil = require( '@stdlib/math-base-special-ceil' ); -var floor = require( '@stdlib/math-base-special-floor' ); -var ceil2 = require( '@stdlib/math-base-special-ceil2' ); -var log2 = require( '@stdlib/math-base-special-log2' ); -var min = require( '@stdlib/math-base-special-min' ); -var defaults = require( './defaults.js' ); -var validate = require( './validate.js' ); -var createPool = require( './pool.js' ); -var BYTES_PER_ELEMENT = require( './bytes_per_element.json' ); - - -// VARIABLES // - -var DEFAULT_DTYPE = ARRAY_DEFAULTS.get( 'dtypes.default' ); -var Complex64Array = ctors( 'complex64' ); -var Complex128Array = ctors( 'complex128' ); -var BooleanArray = ctors( 'bool' ); - - -// FUNCTIONS // - -/** -* Tests whether an array is a single-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a single-precision complex floating-point number array -*/ -function isCmplx64Array( arr ) { - return ( arr instanceof Complex64Array ); -} - -/** -* Tests whether an array is a double-precision complex floating-point number array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a double-precision complex floating-point number array -*/ -function isCmplx128Array( arr ) { - return ( arr instanceof Complex128Array ); -} - -/** -* Tests whether an array is a boolean array. -* -* @private -* @param {Collection} arr - input array -* @returns {boolean} boolean indicating whether an input array is a boolean array -*/ -function isBoolArray( arr ) { - return ( arr instanceof BooleanArray ); -} - - -// MAIN // - -/** -* Creates a typed array pool. -* -* @param {Options} [options] - pool options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} allocator -* -* @example -* var typedarraypool = factory(); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -function factory( options ) { - var nbytes; - var pool; - var opts; - var err; - - opts = defaults(); - if ( arguments.length ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - pool = createPool( ceil( log2( opts.highWaterMark ) ) ); - nbytes = 0; - - setReadOnly( malloc, 'malloc', malloc ); // circular reference - setReadOnly( malloc, 'calloc', calloc ); - setReadOnly( malloc, 'free', free ); - setReadOnly( malloc, 'clear', clear ); - setReadOnly( malloc, 'highWaterMark', opts.highWaterMark ); - setReadOnlyAccessor( malloc, 'nbytes', getBytes ); - - return malloc; - - /** - * Returns the number of allocated bytes. - * - * @private - * @returns {NonNegativeInteger} number of allocated bytes - */ - function getBytes() { - return nbytes; - } - - /** - * Returns an array buffer. - * - * @private - * @param {NonNegativeInteger} n - number of bytes - * @returns {(ArrayBuffer|null)} array buffer or null - */ - function arraybuffer( n ) { - var buf; - var i; - - // Convert the number of bytes to an index in our pool table: - i = log2( n ); - - // If we already have an available array buffer, use it... - if ( i < pool.length && pool[ i ].length ) { - return pool[ i ].pop(); - } - // Before allocating a new array buffer, ensure that we have not exceeded the maximum number of bytes we are allowed to allocate... - if ( nbytes+n > opts.highWaterMark ) { - return null; - } - buf = new ArrayBuffer( n ); - - // Update the running counter of allocated bytes: - nbytes += n; - - return buf; - } - - /** - * Returns a typed array. - * - * @private - * @param {Function} ctor - typed array constructor - * @param {NonNegativeInteger} len - view length - * @param {string} dtype - data type - * @returns {(TypedArray|null)} typed array or null - */ - function typedarray( ctor, len, dtype ) { - var buf; - if ( len === 0 ) { - return new ctor( 0 ); - } - buf = arraybuffer( ceil2( len )*BYTES_PER_ELEMENT[ dtype ] ); - if ( buf === null ) { - return buf; - } - return new ctor( buf, 0, len ); - } - - /** - * Returns an uninitialized typed array. - * - * ## Notes - * - * - Memory is **not** initialized. - * - Memory is lazily allocated. - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {(NonNegativeInteger|Collection)} [arg] - an array length or an array-like object - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length or an array-like object - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function malloc() { - var nargs; - var dtype; - var ctor; - var arr; - var out; - var set; - var get; - var len; - var i; - - nargs = arguments.length; - if ( nargs && isString( arguments[ nargs-1 ] ) ) { - nargs -= 1; - dtype = arguments[ nargs ]; - } else { - dtype = DEFAULT_DTYPE; - } - ctor = ctors( dtype ); - if ( ctor === null ) { - throw new TypeError( format( '01H2Y', dtype ) ); - } - if ( nargs <= 0 ) { - return new ctor( 0 ); - } - // Check if provided a typed array length... - if ( isNonNegativeInteger( arguments[ 0 ] ) ) { - return typedarray( ctor, arguments[ 0 ], dtype ); - } - // Check if provided an array-like object containing data elements... - if ( isCollection( arguments[ 0 ] ) ) { - arr = arguments[ 0 ]; - len = arr.length; - if ( isComplex128Array( arr ) ) { - arr = reinterpret128( arr, 0 ); - } else if ( isComplex64Array( arr ) ) { - arr = reinterpret64( arr, 0 ); - } else if ( isBooleanArray( arr ) ) { - arr = reinterpretBoolean( arr, 0 ); - } else if ( isComplexDataType( dtype ) ) { - // Assume we've been provided an array of interleaved real and imaginary components... - len /= 2; - } - out = typedarray( ctor, len, dtype ); - if ( out === null ) { - return out; - } - if ( isCmplx128Array( out ) || isCmplx64Array( out ) || isBoolArray( out ) ) { - out.set( arr ); - return out; - } - // Resolve element accessors in order to account for the possibility that `arr` is a complex number array. As we don't prohibit other "unsafe" casts (e.g., providing a `Float64Array` and specifying a `dtype` of `uint8`), we don't prohibit providing a complex number array and specifying a real `dtype`. The results will probably be unexpected/gibberish, but I am not sure we should be overly pedantic in ensuring users don't do ill-advised things... - get = resolveGetter( arr ); - set = resolveSetter( out ); - for ( i = 0; i < len; i++ ) { - set( out, i, get( arr, i ) ); - } - return out; - } - throw new TypeError( format( '01H2r', arguments[ 0 ] ) ); - } - - /** - * Returns a zero-initialized typed array. - * - * ## Notes - * - * - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). - * - * @private - * @param {NonNegativeInteger} [len=0] - array length - * @param {string} [dtype="float64"] - data type - * @throws {TypeError} must provide a valid array length - * @throws {TypeError} must provide a recognized data type - * @returns {(TypedArray|null)} typed array or null - */ - function calloc() { - var nargs; - var out; - var tmp; - var i; - - nargs = arguments.length; - if ( nargs === 0 ) { - out = malloc(); - } else if ( nargs === 1 ) { - out = malloc( arguments[ 0 ] ); - } else { - out = malloc( arguments[ 0 ], arguments[ 1 ] ); - } - if ( out !== null ) { - // Initialize the memory... - if ( isCmplx128Array( out ) ) { - tmp = reinterpret128( out, 0 ); - } else if ( isCmplx64Array( out ) ) { - tmp = reinterpret64( out, 0 ); - } else if ( isBoolArray( out ) ) { - tmp = reinterpretBoolean( out, 0 ); - } else { - tmp = out; - } - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = 0.0; - } - } - return out; - } - - /** - * Frees a typed array or typed array buffer. - * - * ## Notes - * - * - Implicitly, we support providing non-internally allocated arrays and array buffer (e.g., "freeing" a typed array allocated in userland); however, the freed array buffer is likely to have excess capacity when compared to other members in its pool. - * - * @private - * @param {(TypedArray|ArrayBuffer)} buf - typed array or array buffer to free - * @throws {TypeError} must provide a typed array or typed array buffer - * @returns {boolean} boolean indicating whether the typed array or array buffer was successfully freed - */ - function free( buf ) { - var n; - var p; - var i; - if ( isTypedArrayLike( buf ) && buf.buffer ) { - buf = buf.buffer; - } else if ( !isArrayBuffer( buf ) ) { - throw new TypeError( format( '01H2s', buf ) ); - } - if ( buf.byteLength > 0 ) { - n = floor( log2( buf.byteLength ) ); - - // Prohibit "freeing" array buffers which would potentially allow users to circumvent high water mark limits: - n = min( pool.length-1, n ); - - // Ensure that we do not attempt to free the same buffer more than once... - p = pool[ n ]; - for ( i = 0; i < p.length; i++ ) { - if ( p[ i ] === buf ) { - return false; - } - } - // Add the buffer to our pool of free buffers: - p.push( buf ); - } - return true; - } - - /** - * Clears the typed array pool allowing garbage collection of previously allocated (and currently free) array buffers. - * - * @private - */ - function clear() { - var i; - for ( i = 0; i < pool.length; i++ ) { - pool[ i ].length = 0; - } - nbytes = 0; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 6c12a4e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Typed array pool. -* -* @module @stdlib/array-pool -* -* @example -* var typedarraypool = require( '@stdlib/array-pool' ); -* -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 8f69ee3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,63 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var factory = require( './factory.js' ); - - -// MAIN // - -/** -* Returns an uninitialized typed array. -* -* ## Notes -* -* - Memory is **not** initialized. -* - Memory is lazily allocated. -* - If the function returns `null`, the function was unable to allocate a new typed array from the typed array pool (most likely due to insufficient memory). -* -* @name typedarraypool -* @type {Function} -* @param {(NonNegativeInteger|ArrayLikeObject)} [arg] - an array length or an array-like object -* @param {string} [dtype="float64"] - data type -* @throws {TypeError} must provide a valid array length or an array-like object -* @throws {TypeError} must provide a recognized data type -* @returns {(TypedArray|null)} typed array or null -* -* @example -* // Allocate an array of doubles: -* var arr = typedarraypool( 5, 'float64' ); -* // e.g., returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] -* -* arr[ 0 ] = 3.14; -* arr[ 1 ] = 3.14; -* -* // ... -* -* // Free the allocated memory to be used in a future allocation: -* typedarraypool.free( arr ); -*/ -var typedarraypool = factory(); - - -// EXPORTS // - -module.exports = typedarraypool; diff --git a/lib/pool.js b/lib/pool.js deleted file mode 100644 index 5abd287..0000000 --- a/lib/pool.js +++ /dev/null @@ -1,44 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Initializes a cache for pooled typed array buffers. -* -* @private -* @param {NonNegativeInteger} n - base-2 logarithm of the maximum typed array size -* @returns {ArrayArray} initialized cache -*/ -function pool( n ) { - var out; - var i; - - out = []; - for ( i = 0; i < n+1; i++ ) { - out.push( [] ); - } - return out; -} - - -// EXPORTS // - -module.exports = pool; diff --git a/lib/validate.js b/lib/validate.js deleted file mode 100644 index da746bb..0000000 --- a/lib/validate.js +++ /dev/null @@ -1,66 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert-is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {NonNegativeInteger} [options.highWaterMark] - maximum total memory which can be allocated -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'highWaterMark': 1024 -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( '01H2V', options ) ); - } - if ( hasOwnProp( options, 'highWaterMark' ) ) { - opts.highWaterMark = options.highWaterMark; - if ( !isNonNegativeInteger( opts.highWaterMark ) ) { - return new TypeError( format( '01H2t', 'highWaterMark', opts.highWaterMark ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/package.json b/package.json index 2945498..ce31461 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Typed array pool.", "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,83 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-assert-is-complex-floating-point-data-type": "^0.2.1", - "@stdlib/array-base-resolve-getter": "^0.2.2", - "@stdlib/array-base-resolve-setter": "^0.2.2", - "@stdlib/array-buffer": "^0.2.2", - "@stdlib/array-defaults": "^0.3.0", - "@stdlib/array-typed-ctors": "^0.3.0", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-arraybuffer": "^0.2.2", - "@stdlib/assert-is-booleanarray": "^0.0.2", - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-complex128array": "^0.2.2", - "@stdlib/assert-is-complex64array": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/assert-is-string": "^0.2.2", - "@stdlib/assert-is-typed-array-like": "^0.2.2", - "@stdlib/math-base-special-ceil": "^0.2.2", - "@stdlib/math-base-special-ceil2": "^0.3.0", - "@stdlib/math-base-special-floor": "^0.2.3", - "@stdlib/math-base-special-log2": "^0.3.0", - "@stdlib/math-base-special-min": "^0.2.3", - "@stdlib/strided-base-reinterpret-boolean": "^0.0.2", - "@stdlib/strided-base-reinterpret-complex128": "^0.2.2", - "@stdlib/strided-base-reinterpret-complex64": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-define-nonenumerable-read-only-accessor": "^0.2.3", - "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-bool": "^0.1.0", - "@stdlib/array-complex128": "^0.3.0", - "@stdlib/array-complex64": "^0.3.0", - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int16": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint16": "^0.2.2", - "@stdlib/array-uint32": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/array-uint8c": "^0.2.2", - "@stdlib/assert-instance-of": "^0.2.2", - "@stdlib/assert-is-complex-typed-array": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-typed-array": "^0.2.2", - "@stdlib/boolean-ctor": "^0.2.2", - "@stdlib/complex-float32-ctor": "^0.0.2", - "@stdlib/complex-float32-imag": "^0.1.1", - "@stdlib/complex-float32-real": "^0.1.1", - "@stdlib/complex-float64-ctor": "^0.0.3", - "@stdlib/complex-float64-imag": "^0.1.1", - "@stdlib/complex-float64-real": "^0.1.1", - "@stdlib/math-base-special-pow": "^0.3.0", - "@stdlib/random-base-randu": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a864c24 --- /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.factory.js b/test/test.factory.js deleted file mode 100644 index 95d35c9..0000000 --- a/test/test.factory.js +++ /dev/null @@ -1,2401 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var real = require( '@stdlib/complex-float64-real' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imag = require( '@stdlib/complex-float64-imag' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function (no options)', function test( t ) { - t.strictEqual( typeof factory(), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns a function (options)', function test( t ) { - t.strictEqual( typeof factory( {} ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an invalid options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided a `highWaterMark` option which is not a nonnegative integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory({ - 'highWaterMark': value - }); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (length)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a function which returns a typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=bool)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, length)', function test( t ) { - var typedarraypool = factory(); - var arr; - - arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=bool, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=bool, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ true, false, false, true ]; - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( v, arr[ 0 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( v, arr[ 1 ], 'returns expected value' ); - - v = out.get( 2 ); - t.strictEqual( v, arr[ 2 ], 'returns expected value' ); - - v = out.get( 3 ); - t.strictEqual( v, arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (default, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=float32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=bool, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Uint8Array( 0 ); - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8Array( [ 1, 0, 0, 1 ] ); - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( v, true, 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( v, false, 'returns expected value' ); - - v = out.get( 2 ); - t.strictEqual( v, false, 'returns expected value' ); - - v = out.get( 3 ); - t.strictEqual( v, true, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex128, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=complex64, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - var v; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint32, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint16, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=int8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a function which returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var typedarraypool; - var arr; - var out; - - typedarraypool = factory(); - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a `malloc` method which is a circular reference', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=bool)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=bool, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'bool' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( Boolean( i%2 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( v, false, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var v; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var typedarraypool; - var arr; - var tmp; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers', function test( t ) { - var typedarraypool; - var arr; - var buf; - var i; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var typedarraypool; - var bool; - var arr; - var buf; - - typedarraypool = factory(); - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the returned function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var typedarraypool; - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - typedarraypool = factory(); - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the returned function is a property which returns the pool\'s high water mark', function test( t ) { - var typedarraypool = factory(); - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'the function supports specifying a high water mark which limits the total amount of memory a pool can allocate', function test( t ) { - var typedarraypool; - var arr1; - var arr2; - - typedarraypool = factory({ - 'highWaterMark': 64 // bytes - }); - - typedarraypool.clear(); - - arr1 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr1.length, 8, 'returns expected value' ); - t.strictEqual( arr1.byteLength, 64, 'returns expected value' ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - typedarraypool.free( arr1 ); - - // Specify an array length: - arr2 = typedarraypool( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( 1e6, 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Provide an array from which to copy elements: - arr2 = typedarraypool( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.malloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - arr2 = typedarraypool.calloc( new Float64Array( 20 ), 'float64' ); - t.strictEqual( arr2, null, 'returns expected value' ); - - // Create an array which is less than or equal to the high water mark: - arr2 = typedarraypool( 8, 'float64' ); - t.strictEqual( arr2.length, 8, 'returns expected value' ); - t.strictEqual( arr2.byteLength, 64, 'returns expected value' ); - - typedarraypool.free( arr2 ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a property which returns the total number of accumulated bytes', function test( t ) { - var typedarraypool; - var arr; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the returned function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var typedarraypool; - var arrs; - var i; - - typedarraypool = factory(); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index a4778b2..0000000 --- a/test/test.js +++ /dev/null @@ -1,1935 +0,0 @@ -/* eslint-disable max-lines */ - -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint32Array = require( '@stdlib/array-uint32' ); -var Int16Array = require( '@stdlib/array-int16' ); -var Uint16Array = require( '@stdlib/array-uint16' ); -var Int8Array = require( '@stdlib/array-int8' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var Complex128Array = require( '@stdlib/array-complex128' ); -var BooleanArray = require( '@stdlib/array-bool' ); -var instanceOf = require( '@stdlib/assert-instance-of' ); -var randu = require( '@stdlib/random-base-randu' ); -var Complex128 = require( '@stdlib/complex-float64-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var Boolean = require( '@stdlib/boolean-ctor' ); -var real = require( '@stdlib/complex-float64-real' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imag = require( '@stdlib/complex-float64-imag' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var typedarraypool = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof typedarraypool, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an unrecognized data type (only argument)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (length)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( 10, value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (typed array)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( new Float64Array( 10 ), value ); - }; - } -}); - -tape( 'the function throws an error if provided an unrecognized data type (array-like object)', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'typedarray', - 'Int32', - 'Uint32', - 'Int16', - 'Uint16', - 'Int8', - 'Uint8', - 'Uint8c', - 'uint8_clamped', - 'Float64', - 'Float32', - 'FLOAT64', - 'FLOAT32' - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( [ 1, 2, 3 ], value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (no data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid array length or array-like object argument (data type argument)', function test( t ) { - var values; - var i; - - values = [ - 3.14, - -1, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool( value, 'float64' ); - }; - } -}); - -tape( 'the function returns a typed array (default)', function test( t ) { - var arr = typedarraypool(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=bool)', function test( t ) { - var arr = typedarraypool( 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, length)', function test( t ) { - var arr = typedarraypool( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, length)', function test( t ) { - var arr = typedarraypool( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, length)', function test( t ) { - var arr = typedarraypool( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=bool, length)', function test( t ) { - var arr = typedarraypool( 10, 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, length)', function test( t ) { - var arr = typedarraypool( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { - var arr = typedarraypool( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, length)', function test( t ) { - var arr = typedarraypool( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, length)', function test( t ) { - var arr = typedarraypool( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, length)', function test( t ) { - var arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 10, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=bool, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ true, false, false, true ]; - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( v, arr[ 0 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( v, arr[ 1 ], 'returns expected value' ); - - v = out.get( 2 ); - t.strictEqual( v, arr[ 2 ], 'returns expected value' ); - - v = out.get( 3 ); - t.strictEqual( v, arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, array)', function test( t ) { - var arr; - var out; - var v; - - arr = []; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0, 4.0 ]; - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, array)', function test( t ) { - var arr; - var out; - - arr = []; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = [ 1.0, 2.0, 3.0 ]; - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (default, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float64, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float64' ); - t.strictEqual( instanceOf( out, Float64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=float32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint32Array( 0 ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'float32' ); - t.strictEqual( instanceOf( out, Float32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=bool, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Uint8Array( 0 ); - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8Array( [ 1, 0, 0, 1 ] ); - out = typedarraypool( arr, 'bool' ); - t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 4, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( v, true, 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( v, false, 'returns expected value' ); - - v = out.get( 2 ); - t.strictEqual( v, false, 'returns expected value' ); - - v = out.get( 3 ); - t.strictEqual( v, true, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex128, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex128' ); - t.strictEqual( instanceOf( out, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( real( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( real( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imag( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=complex64, typed array)', function test( t ) { - var arr; - var out; - var v; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - out = typedarraypool( arr, 'complex64' ); - t.strictEqual( instanceOf( out, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 2, 'returns expected value' ); - - v = out.get( 0 ); - t.strictEqual( realf( v ), arr[ 0 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 1 ], 'returns expected value' ); - - v = out.get( 1 ); - t.strictEqual( realf( v ), arr[ 2 ], 'returns expected value' ); - t.strictEqual( imagf( v ), arr[ 3 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int32' ); - t.strictEqual( instanceOf( out, Int32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint32, typed array)', function test( t ) { - var arr; - var out; - - arr = new Uint8ClampedArray( 0 ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Uint8ClampedArray( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint32' ); - t.strictEqual( instanceOf( out, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float64Array( 0 ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int16' ); - t.strictEqual( instanceOf( out, Int16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint16, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int8Array( 0 ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int8Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint16' ); - t.strictEqual( instanceOf( out, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=int8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int16Array( 0 ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int16Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'int8' ); - t.strictEqual( instanceOf( out, Int8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8, typed array)', function test( t ) { - var arr; - var out; - - arr = new Int32Array( 0 ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Int32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8' ); - t.strictEqual( instanceOf( out, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'the function returns a typed array (dtype=uint8c, typed array)', function test( t ) { - var arr; - var out; - - arr = new Float32Array( 0 ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 0, 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); - out = typedarraypool( arr, 'uint8c' ); - t.strictEqual( instanceOf( out, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( out.length, 3, 'returns expected value' ); - t.strictEqual( out[ 0 ], arr[ 0 ], 'returns expected value' ); - t.strictEqual( out[ 1 ], arr[ 1 ], 'returns expected value' ); - t.strictEqual( out[ 2 ], arr[ 2 ], 'returns expected value' ); - - typedarraypool.free( out ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a `malloc` method which is a circular reference', function test( t ) { - t.strictEqual( typedarraypool, typedarraypool.malloc, 'is circular reference' ); - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default)', function test( t ) { - var arr = typedarraypool.calloc(); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64)', function test( t ) { - var arr = typedarraypool.calloc( 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32)', function test( t ) { - var arr = typedarraypool.calloc( 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=bool)', function test( t ) { - var arr = typedarraypool.calloc( 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128)', function test( t ) { - var arr = typedarraypool.calloc( 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64)', function test( t ) { - var arr = typedarraypool.calloc( 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32)', function test( t ) { - var arr = typedarraypool.calloc( 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32)', function test( t ) { - var arr = typedarraypool.calloc( 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16)', function test( t ) { - var arr = typedarraypool.calloc( 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16)', function test( t ) { - var arr = typedarraypool.calloc( 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8)', function test( t ) { - var arr = typedarraypool.calloc( 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c)', function test( t ) { - var arr = typedarraypool.calloc( 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 0, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (default, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10 ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float64, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=float32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'float32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=bool, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'bool' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( Boolean( i%2 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'bool' ); - t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( v, false, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex128, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex128' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex128( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( real( v ), 0.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=complex64, length)', function test( t ) { - var arr; - var tmp; - var v; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'complex64' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp.set( new Complex64( randu()*256.0, 1.0 ), i ); - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - v = arr.get( i ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint32, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint32' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint16, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint16' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=int8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'int8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method which returns a zero-initialized typed array (dtype=uint8c, length)', function test( t ) { - var arr; - var tmp; - var i; - - typedarraypool.clear(); - - tmp = typedarraypool.malloc( 10, 'uint8c' ); - for ( i = 0; i < tmp.length; i++ ) { - tmp[ i ] = randu() * 256.0; - } - typedarraypool.free( tmp ); - - arr = typedarraypool.calloc( 10, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.notEqual( arr, tmp, 'returns a new view' ); - t.strictEqual( arr.buffer, tmp.buffer, 'same array buffer' ); - - t.strictEqual( arr.length, 10, 'returns expected value' ); - for ( i = 0; i < arr.length; i++ ) { - t.strictEqual( arr[ i ], 0, 'returns expected value' ); - } - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( arr ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers', function test( t ) { - var arr; - var buf; - var i; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - typedarraypool.free( buf ); - - for ( i = 0; i < 10; i++ ) { - arr = typedarraypool( 10, 'uint8c' ); - t.strictEqual( arr.buffer, buf, 'returns expected value' ); - typedarraypool.free( arr.buffer ); - } - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed arrays which does not allow for "freeing" allocated typed arrays more than once before being reallocated', function test( t ) { - var bool; - var arr; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - bool = typedarraypool.free( arr ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( arr ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array buffers which does not allow for "freeing" allocated typed array buffers more than once before being reallocated', function test( t ) { - var bool; - var arr; - var buf; - - typedarraypool.clear(); - - arr = typedarraypool( 10, 'uint8c' ); - buf = arr.buffer; - bool = typedarraypool.free( buf ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = typedarraypool.free( buf ); - t.strictEqual( bool, false, 'returns expected value' ); - - typedarraypool.clear(); - t.end(); -}); - -tape( 'attached to the exported function is a method for "freeing" allocated typed array and typed array buffers which throws if not provided either a typed array or typed array buffer', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - typedarraypool.free( value ); - }; - } -}); - -tape( 'attached to the exported function is a property which returns the pool\'s high water mark', function test( t ) { - t.strictEqual( typeof typedarraypool.highWaterMark, 'number', 'has property' ); - t.end(); -}); - -tape( 'attached to the exported function is a property which returns the total number of accumulated bytes', function test( t ) { - var arr; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arr = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.free( arr ); - typedarraypool.clear(); - - t.end(); -}); - -tape( 'attached to the exported function is a method for clearing a typed array pool of freed typed array buffers', function test( t ) { - var arrs; - var i; - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - arrs = new Array( 10 ); - for ( i = 0; i < arrs.length; i++ ) { - arrs[ i ] = typedarraypool( 10, 'uint8' ); - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - } - for ( i = 0; i < arrs.length; i++ ) { - typedarraypool.free( arrs[ i ] ); - } - t.strictEqual( typedarraypool.nbytes > 0 && typedarraypool.nbytes < typedarraypool.highWaterMark, true, 'returns expected value' ); - - typedarraypool.clear(); - t.strictEqual( typedarraypool.nbytes, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'attached to the exported function is a method for creating typed array memory pools', function test( t ) { - t.strictEqual( typeof typedarraypool.factory, 'function', 'has method' ); - t.end(); -});